I'm using Android's Animation Drawable
to show an animation. However I want it to be as snappy as possible, because I want it to show whenever the screen is touched. The way it is now it is too slow. It takes around 500 ms to show up. Is there a way that I can preload the animation or maybe some alternative?
Here is the code:
public void setYes(){
ImageView prev_view = (ImageView) ref_container.getChildAt(ref_container.getChildCount()-2);
prev_view.setImageResource(R.drawable.accept);
acceptAnimation = (AnimationDrawable) prev_view.getDrawable();
acceptAnimation.start();
}
And here it is the XML inside drawable
folder containing the animation frames:
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/accept01" android:duration="33" />
<item android:drawable="@drawable/accept02" android:duration="33" />
<item android:drawable="@drawable/accept03" android:duration="33" />
<item android:drawable="@drawable/accept04" android:duration="33" />
<item android:drawable="@drawable/accept05" android:duration="33" />
<item android:drawable="@drawable/accept06" android:duration="33" />
<item android:drawable="@drawable/accept07" android:duration="33" />
<item android:drawable="@drawable/accept08" android:duration="33" />
<item android:drawable="@drawable/accept09" android:duration="33" />
<item android:drawable="@drawable/accept10" android:duration="33" />
<item android:drawable="@drawable/accept11" android:duration="33" />
<item android:drawable="@drawable/accept12" android:duration="33" />
<item android:drawable="@drawable/accept13" android:duration="33" />
<item android:drawable="@drawable/accept14" android:duration="33" />
<item android:drawable="@drawable/accept15" android:duration="33" />
<item android:drawable="@drawable/accept16" android:duration="33" />
</animation-list>
I call this function when I detect a certain touch pattern. I think I can't load it before because I'm using it in different views ref_container.getChildCount()-2
. Do you guys have any solution, suggestion to speed it up?