版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ITzhongzi/article/details/88869614
思路: 在drawable之中创建一个xml文件,把相关的动画图片引进来。再用AnimationDrawable来加载即可
图片素材地址:
素材地址: 艾斯动画素材地址
示例代码:
layout.xml文件(在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/a" android:duration="200" />
<item android:drawable="@drawable/b" android:duration="200" />
<item android:drawable="@drawable/c" android:duration="200" />
<item android:drawable="@drawable/d" android:duration="200" />
<item android:drawable="@drawable/e" android:duration="200" />
<item android:drawable="@drawable/f" android:duration="200" />
<item android:drawable="@drawable/g" android:duration="200" />
<item android:drawable="@drawable/h" android:duration="200" />
<item android:drawable="@drawable/i" android:duration="200" />
<item android:drawable="@drawable/g" android:duration="200" />
<item android:drawable="@drawable/k" android:duration="200" />
<item android:drawable="@drawable/l" android:duration="200" />
<item android:drawable="@drawable/m" android:duration="200" />
<item android:drawable="@drawable/n" android:duration="200" />
<item android:drawable="@drawable/o" android:duration="200" />
</animation-list>
java文件:
private ImageView mAnimalImage;
private AnimationDrawable mAnimalDrawable;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAnimalImage = (ImageView) findViewById(R.id.animal_image);
mAnimalImage.setBackgroundResource(R.drawable.layout);
mAnimalDrawable = (AnimationDrawable) mAnimalImage.getBackground();
mAnimalImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAnimalDrawable.start();
}
});
}
效果: