下面是$ C $下的xml:
< ImageView的
机器人:ID =@ + ID / imageView1
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:SRC =@可绘制/ minepic/>
下面的minepic是一个GIF动画形象,但在运行应用程序后,它只是显示静态图像。
时的明镜有关如何在android应用动画.gif图片任何解决方案。
解决方案要给予precise这里完整的答案是什么,你需要聪明的执行步骤:
您需要有不同的巴纽
图像将作为
帧的动画。将它们保存在 RES /绘制
文件夹。
科瑞 anim.xml
在 RES文件/绘制
文件夹下面的内容:
< XML版本=1.0编码=UTF-8&GT?;
<动画列表的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:单稳=假>
<项目机器人:可绘制=@可绘制/ IMAGE_3机器人:时间=250/>
<项目机器人:可绘制=@可绘制/ IMAGE_2机器人:时间=250/>
<项目机器人:可绘制=@可绘制/ IMAGE_1机器人:时间=250/>
<项目机器人:可绘制=@可绘制/图像机器人:时间=250/>
< /动画列表>
在布局 XML
文件中要显示动画:
// ...
< ImageView的
机器人:ID =@ + ID / ivAnimation
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerHorizontal =真
机器人:contentDescription =动画/>
// ...
在它加载的布局XML文件并调用Java文件
的setContentView
:
// ...
@覆盖
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
最后ImageView的animImageView =(ImageView的)findViewById(R.id.ivAnimation);
animImageView.setBackgroundResource(R.drawable.anim);
animImageView.post(新的Runnable(){
@覆盖
公共无效的run(){
AnimationDrawable frameAnimation =
(AnimationDrawable)animImageView.getBackground();
frameAnimation.start();
}
});
// ...等code ...
}
// ...
希望它可以帮助别人。
Here is the code for xml:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/minepic" />
Here the minepic is a gif animated image but after running the application its just showing a static image.
Is der any solution about how to animate the .gif images in android application.
解决方案
To give a precise and complete answer here is what you need to do step wise:
You would need to have different .png
images which will act as
frames for your animation. Save them in res/drawable
folder.
Creat anim.xml
file in res/drawable
folder with following content:
<?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/image_3" android:duration="250" />
<item android:drawable="@drawable/image_2" android:duration="250" />
<item android:drawable="@drawable/image_1" android:duration="250" />
<item android:drawable="@drawable/image" android:duration="250" />
</animation-list>
In the layout xml
file inside which you want to show the animation:
//...
<ImageView
android:id="@+id/ivAnimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="Animation" />
//...
In the Java file which loads the the layout xml file and calls
setContentView
:
//...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView animImageView = (ImageView) findViewById(R.id.ivAnimation);
animImageView.setBackgroundResource(R.drawable.anim);
animImageView.post(new Runnable() {
@Override
public void run() {
AnimationDrawable frameAnimation =
(AnimationDrawable) animImageView.getBackground();
frameAnimation.start();
}
});
// ... other code ...
}
// ...
Hope it helps someone.