Dan*_*nny 17 android gif jquery-animate animationdrawable
这是xml的代码:
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/minepic" />
Run Code Online (Sandbox Code Playgroud)
这里的minepic是一个gif动画图像,但在运行应用程序后它只显示一个静态图像.
有没有关于如何在Android应用程序中动画.gif图像的解决方案?
Sho*_*uri 37
为了给出一个精确而完整的答案,您需要逐步做到:
您需要使用不同的.png
图像作为动画的帧.将它们保存在res/drawable
文件夹中
使用以下内容anim.xml
在res/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/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>
Run Code Online (Sandbox Code Playgroud)在xml
要在其中显示动画的布局文件中:
//...
<ImageView
android:id="@+id/iv_animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:contentDescription="Animation" />
//...
Run Code Online (Sandbox Code Playgroud)在Java文件中加载布局xml文件并调用
setContentView
:
//...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView animImageView = (ImageView) findViewById(R.id.iv_animation);
animImageView.setBackgroundResource(R.drawable.anim);
animImageView.post(new Runnable() {
@Override
public void run() {
AnimationDrawable frameAnimation =
(AnimationDrawable) animImageView.getBackground();
frameAnimation.start();
}
});
// ... other code ...
}
// ...
Run Code Online (Sandbox Code Playgroud)为了阻止你可以调用动画.stop()
上AnimationDrawable
.有关可用方法的更多详细信息,请参阅AnimationDrawable文档.希望它可以帮助某人.
Pio*_*otr 14
我不建议使用Movie
或WebView
类,ImageView
而是使用源drawable设置animation-list
.看看example(mydrawable.xml
):
<?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_1" android:duration="100" />
<item android:drawable="@drawable/image_2" android:duration="100" />
<item android:drawable="@drawable/image_3" android:duration="100" />
</animation-list>
// in your layout : <ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_drawable" />
Run Code Online (Sandbox Code Playgroud)
显然,在使用此解决方案之前,您必须将.gif切片为单独的图像.
归档时间: |
|
查看次数: |
28213 次 |
最近记录: |