MBH MBH - 1 year ago 62
Android Question

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)?

Answer Source

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download