Question

Is it possible to make fade out animation for multiple button smoothly?

Created fadeout.xml @res/anim

<?xml version="1.0" encoding="UTF-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
    android:fromAlpha="1.0"
    android:toAlpha="0.0"
    android:interpolator="@android:anim/accelerate_interpolator" 
    android:duration="1500"
    android:repeatCount="infinite" />
</set>

Using this to set animation

Animation fadeout = AnimationUtils.loadAnimation(this, R.anim.fadeout);

And apply the animation to some buttons after click

public void click (View v){
     button1.startAnimation(fadeout);
     button2.startAnimation(fadeout);
     button3.startAnimation(fadeout);
     button4.startAnimation(fadeout);
     button5.startAnimation(fadeout);
     button6.startAnimation(fadeout);
     button7.startAnimation(fadeout);
     button8.startAnimation(fadeout);
     button9.startAnimation(fadeout);
     button10.startAnimation(fadeout);
     button11.startAnimation(fadeout);
     button12.startAnimation(fadeout);
     button13.startAnimation(fadeout);
     button14.startAnimation(fadeout);
     button15.startAnimation(fadeout);
}

It's not a problem when applying to 3-5 buttons, but when applying to many buttons like above it's become laggy.

So is there anyways to make this animation applied to many buttons without laggy?

Because I need to apply this animation to many, so many buttons, around 162 buttons.

I'm using Galaxy Nexus for testing.

Était-ce utile?

La solution

It's unnecessary to apply an animation to each button individually; Instead, stick them all inside of another layout (i.e., GridLayout), and apply the animation to that.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top