Reputation: 111
I followed the android developer site to add gif image in my application. But the image is not showing as animated, it shows like a normal image.
Animation in drawable
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/los01" android:duration="50" />
<item android:drawable="@drawable/los02" android:duration="50" />
</animation-list>
Coding
layout.setBackgroundResource(R.drawable.bg);
img.setBackgroundResource(R.drawable.mylosanim);
AnimationDrawable frameAnimation = (AnimationDrawable) img.getBackground();
frameAnimation.start();
tv1.setText("Sorry!!!Play Again!!!");
tv3.setText("Your Level-1 Score:"+Integer.toString(score));
layout.setClickable(true);
frameAnimation.stop();
Upvotes: 3
Views: 6033
Reputation: 132992
try as
AnimationDrawable frameAnimation = (AnimationDrawable)img.getBackground();
if (frameAnimation.isRunning()){
frameAnimation.stop();
}else{
frameAnimation.stop();
frameAnimation.start();
tv1.setText("Sorry!!!Play Again!!!");
tv3.setText("Your Level-1 Score:"+Integer.toString(score));
layout.setClickable(true);
}
Upvotes: 1
Reputation: 15774
There are several approaches including the use of Movie
class.
Take a look at Tutorial: How to play animated GIFs in Android and the related posts for alternatives.
Upvotes: 2