项目中需要实现帧动画的需求,查阅相关资料,将实现的效果进行了整理,内容如下
图片如上,是几张不同的图片,关键代码如下
布局文件中imageview 站位
<ImageView
android:id="@+id/iv_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:visibility="invisible"
/>
public ImageView iv_dialog;
public AnimationDrawable amAnimationDrawable;
iv_dialog=(ImageView)findViewById(R.id.iv_dialog);
iv_dialog.setBackgroundResource(R.anim.progress);
amAnimationDrawable=(AnimationDrawable)iv_dialog.getBackground();
amAnimationDrawable.start();
在res文件夹下建立anim文件夹,里面是progress.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/progress_1" android:duration="200"/>
<item android:drawable="@drawable/progress_2" android:duration="200"/>
<item android:drawable="@drawable/progress_3" android:duration="200"/>
<item android:drawable="@drawable/progress_4" android:duration="200"/>
<item android:drawable="@drawable/progress_5" android:duration="200"/>
<item android:drawable="@drawable/progress_6" android:duration="200"/>
<item android:drawable="@drawable/progress_7" android:duration="200"/>
<item android:drawable="@drawable/progress_8" android:duration="60"/>
</animation-list>
至此,帧动画的功能实现了