Is there any way to animate multiple views at the same time?
What I want to do is translate animations:
I have 5 TextViews and 4 coloured strips (plain RelativeLayouts with a background). At the start of the animations, the stips are stacked with the TextViews in a horizontal row. At the end I want all the TextViews stacked between the strips:
This is a very simple drawing, but it demonstrates what I want to do. Is there any way of doing this with animations, or do I have to use canvas animations.
As shown in code above, ValueAnimator is almost like ObjectAnimator , except it doesn't have a specific view to target. It has to have a listener — i.e. addUpdateListner — to listen to the value change and behave accordingly. This added more code, but better customization for it.
The property animation system is a robust framework that allows you to animate almost anything. You can define an animation to change any object property over time, regardless of whether it draws to the screen or not.
You can use the ObjectAnimator for animating the multiple view as follows:
ArrayList<ObjectAnimator> arrayListObjectAnimators = new ArrayList<ObjectAnimator>(); //ArrayList of ObjectAnimators ObjectAnimator animY = ObjectAnimator.ofFloat(view, "y", 100f); arrayListObjectAnimators.add(animY); ObjectAnimator animX = ObjectAnimator.ofFloat(view, "x", 0f); arrayListObjectAnimators.add(animX); ... ObjectAnimator[] objectAnimators = arrayListObjectAnimators.toArray(new ObjectAnimator[arrayListObjectAnimators.size()]); AnimatorSet animSetXY = new AnimatorSet(); animSetXY.playTogether(objectAnimators); animSetXY.setDuration(1000);//1sec animSetXY.start();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With