Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Start two animation in the same Layout

Im trying to do an alpha and translate in a RelativeLayout. I define both:

AlphaAnimation alpha;
alpha = new AlphaAnimation(0.0f, 1.0f);
alpha.setDuration(1500);
alpha.setFillAfter(true);

TranslateAnimation translate;
translate = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0,                                                                       
                 Animation.RELATIVE_TO_SELF, 0,
                 Animation.RELATIVE_TO_SELF, 1, 
                 Animation.RELATIVE_TO_SELF, 0);
translate.setDuration(1000);

So I start the animation in my RelativeLayout

RelativeLayout.startAnimation(translate);
RelativeLayout.startAnimation(alpha);

The problem is that in this case, only the alpha animation start and not the translation. Can someone help me? The question is how can I start two different animations at the same time in the same object(Relative Layout in my case)


I resolve the question. I added it:

AnimationSet animationSet = new AnimationSet(true);
animationSet.addAnimation(alpha);
animationSet.addAnimation(translate);

RelativeLayout.startAnimation(animationSet);
like image 394
Georgevik Avatar asked Jan 19 '13 13:01

Georgevik


People also ask

Can you have two animations in CSS?

You cannot play two animations since the attribute can be defined only once.


1 Answers

You can use animation set ıf you want to run two animation in the same time:

http://developer.android.com/reference/android/view/animation/AnimationSet.html

For exeample;

as = new AnimationSet(true);
as.setFillEnabled(true);
as.setInterpolator(new BounceInterpolator());

TranslateAnimation ta = new TranslateAnimation(-300, 100, 0, 0); 
ta.setDuration(2000);
as.addAnimation(ta);

TranslateAnimation ta2 = new TranslateAnimation(100, 0, 0, 0); 
ta2.setDuration(2000);
ta2.setStartOffset(2000); // allowing 2000 milliseconds for ta to finish
as.addAnimation(ta2);
like image 152
ihsanbal Avatar answered Sep 21 '22 09:09

ihsanbal