Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hiding and showing multiple views using the same animation

I want to apply an animation for multiple views at the same time, how can I apply said animation to several types of views (buttons, imageviews, and other views)?

like image 632
MBH Avatar asked Feb 01 '26 18:02

MBH


1 Answers

If what you want is to apply an animation on several views at the same time, simply call the startAnimation method on those views one after the other. They will be simultaneous

//Get your views
View view1 = findViewById(R.id.view1);
View view2 = findViewById(R.id.view2);
View view3 = findViewById(R.id.view3);

//Get your animation
Animation youranimation = AnimationUtils.loadAnimation(this, R.anim.animationid);

//Start animations
view1.startAnimation(youranimation);
view2.startAnimation(youranimation);
view3.startAnimation(youranimation);

Or if you have a lot of views:

Animation youranimation = AnimationUtils.loadAnimation(this, R.anim.animationid);
int[] viewIds = new int[]{R.id.view1,R.id.view2,R.id.view3,R.id.view4};
for(int id : viewIds) findViewById(id).startAnimation(youranimation);

That is, assuming you want to animate several views at the same time, if what your're doing is one after the other we would dive into animation listeners and that's another story

like image 101
Juan Cortés Avatar answered Feb 04 '26 14:02

Juan Cortés



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!