如何在Android中的ImageView中添加GIF图像?

3
我按照Android开发者网站上的指示在应用程序中添加GIF图像。但是该图像未显示为动画,而是像普通图像一样显示。
可在drawable文件夹下创建一个名为animated_image.xml的XML文件,其中包含以下内容: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>

编码

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();
2个回答

2

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);
        } 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接