Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Animation - Multiple Views

Tags:

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:

enter image description here

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.

like image 814
Matthew Avatar asked Feb 09 '12 19:02

Matthew


People also ask

What is the difference between ValueAnimator and ObjectAnimator?

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.

What is property animation?

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.


1 Answers

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(); 
like image 134
Pradeep Avatar answered Sep 26 '22 01:09

Pradeep