0

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.

stanete
  • 4,062
  • 9
  • 21
  • 30

2 Answers2

2

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);
 img.setBackgroundResource(R.drawable.spin_animation);

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

 // Start the animation (looped playback by default).
 frameAnimation.start();

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

Psest328
  • 6,575
  • 11
  • 55
  • 90
1

You can call stop() like this:

try {
    ivContent.setImageResource(mDrawableResource);
    mDrawable = (AnimationDrawable) ivContent.getDrawable();
    mDrawable.stop();
} catch (Exception e) {
    e.printStackTrace();
}
ttdevs
  • 101
  • 2