3

我按照 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();
4

2 回答 2

2

有几种方法,包括使用Movie类。

查看教程:如何在 Android 中播放动画 GIF以及相关帖子以获取替代方案。

于 2012-06-21T05:33:19.317 回答
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);
        } 
于 2012-06-21T05:36:38.373 回答