我跟着android开发者网站在我的应用程序中添加了gif图像。但是图像没有显示为动画,它显示为正常图像。
可绘制的动画
<?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>
编码
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();
答案 0 :(得分:2)
有几种方法,包括使用Movie
类。
查看Tutorial: How to play animated GIFs in Android以及替代方案的相关帖子。
答案 1 :(得分:1)
尝试
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);
}