How to run two animations on two different views using the lvl 19 API

I have a working example for animating two views with two different animations at the same time. But for some reason this just doesn't work on Android 4.4.2 devices (API level 19).

Animations occur, but setFillAfter is not applied, and at the end of the view are displayed as they were at the starting point.

Here is the code:

// Creating an animation set
AnimationSet animationSet = new AnimationSet(true);
animationSet.setFillAfter(true);

// Creating a Scale Animation
ScaleAnimation scaleAnimation = new ScaleAnimation(
zoomPercent, newZoom, zoomPercent, newZoom, // Start and end values for the Y axis scaling
Animation.RELATIVE_TO_SELF, zoomPointX, // Pivot point of X scaling
Animation.RELATIVE_TO_SELF, zoomPointY); // Pivot point of Y scaling

// Creating a Translate animation
TranslateAnimation anim = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, translateX,
Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, translateY,
Animation.RELATIVE_TO_SELF, 0f);

//Adding the animations to the set
animationSet.addAnimation(anim);
animationSet.addAnimation(scaleAnimation);
animationSet.setDuration(duration);

// Creating Alpha animation
AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f,0f);
alphaAnimation.setFillAfter(true);    
alphaAnimation.setDuration(duration);

relativeLayout.startAnimation(animationSet); //id="@+id/relative_layout"
darkOverlay.startAnimation(alphaAnimation); //darkOverlay is DarkOverlayView extends View, can be seen below

The layout I'm animating is as follows

<RelativeLayout
            android:id="@+id/relative_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <ViewPager
                android:id="@+id/view_pager"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            <com.example.DarkOverlayView
                android:id="@+id/dark_overlay_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
</RelativeLayout>

Any suggestion will help. So far I have tried .setFillEnabled (true) on both sets, but with no effect. I also tried to start the second animation after calling the onAnimationStart callback of the first. It also had no result.

Update: , Animation.getTansformation(long currentTime,               Transformation outTransformation), , - .

+6

Source: https://habr.com/ru/post/1014840/


All Articles