一、幀動畫(Frame動畫):短時間內連續顯示一系列圖像的過程
二、幀動畫的創建
假設 ImageView iv = (ImageView)findViewById(R.id.XXX);
1 需要一系列的圖片:存在res/drawable下
2.在xml文件中配置對應的圖片
-把xml文件添加到對應視圖
res/drawable下新建一個animation-list的xml文件 ,名爲frame_list
<animation-list xmlns:.....
android:oneshot="true"只播放一遍
>
<item
android:drawable="@drawable/xxx //對應動畫的每一幀圖片
android:duration = "200"/>
<item
android:drawable="@drawable/xxx
android:duration = "200"/>
<item
android:drawable="@drawable/xxx
android:duration = "200"/>
</animation-list>
iv.setBackgroundResource(R.drawable.frame_list);//將動畫xml與某個ImageView綁定-獲取AnimationDrawable開始動畫
<span style="font-size:18px;">AnimationDrawable anim_draw;
anim_draw=(AnimationDrawable)iv.getBackground();
anim_draw.start();//開始動畫
anim_draw.stop();//停止動畫</span>
3.通過代碼動態添加
-構造AnimationDrawable類
-把動畫圖片添加到AnimationDrawable中
-把AnimationDrawable設置爲對應視圖的背景
anim_draw = new AnimationDrawable();
anim_draw.addFrame(getResource().getDrawable(R.drawable.xxx),100);//添加幀圖片
......
anim_draw.addFrame(getResource().getDrawable(R.drawable.xxx),100);//添加幀圖片
anim_draw.setOneShot(false);//循環重複播放動畫
iv.setBackground(anim_draw);