David Stanete David Stanete - 1 year ago 125
Android Question

Behavior of Animation and ImageView in Android 4.4.2

Weird thing in Android 4.4.2 - Problem

I set a setAnimation as ImageResource to an ImageView when I click it.

((ImageView) v).setImageResource(R.drawable.set_animation);

Well it shouldn't start because in Android 4.0 ; 4.1; 4.2 and 4.3 I have to call

(AnimationDrawable)((ImageView) v).getDrawable().start();

So in Android 4.4.2 as soon as I set the ImageResource the animation starts.

Someone can tell why this happens and how can I stop the animation from starting? Thak you in advance.

Answer Source

Try changing your implementation to this and see if you have a better experience:

 // Load the ImageView that will host the animation and
 // set its background to our AnimationDrawable XML resource.
 ImageView img = (ImageView)findViewById(R.id.spinning_wheel_image);

 // Get the background, which has been compiled to an AnimationDrawable object.
 AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();

 // Start the animation (looped playback by default).

found it here: http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html

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