1,效果图
ezgif.com-video-to-gif.gif2,方法一
使用代码的方式实现
private void testMethow() {
AnimationDrawable animationDrawable = new AnimationDrawable();
for (int i = 0; i < 2; i++) {//对应准备的图片名
int id = getResources().getIdentifier("red990" + (i+1), "drawable", getPackageName());
Drawable drawable = getResources().getDrawable(id);
animationDrawable.addFrame(drawable,200);
}
animationDrawable.setOneShot(false);
mImgOne.setImageDrawable(animationDrawable);
animationDrawable.start();
}
3,方法二
- 1,在drawable中新建文件如下:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/red9901" android:duration="200"/>
<item android:drawable="@drawable/red9902" android:duration="200"/>
</animation-list>
- 2,在xml中使用
<ImageView
android:id="@+id/img_frame_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/lottery_animlist"
/>
- 3,在Activity中开启动画
//开启动画
//mImgOne.setImageResource(R.drawable.lottery_animlist);
AnimationDrawable drawable = (AnimationDrawable) mImgOne.getDrawable();
drawable.start();*/
//停止的方法
//drawable.stop();
网友评论