android 创建帧动画,Android 逐帧动画创建实例详解
Android 逐幀動畫創(chuàng)建實例詳解
前言:
我們看早期電影的時候,電影通常是一張一張播放,用我們現(xiàn)在專有名詞來說,就是一幀幀來,安卓同樣有這樣動畫效果的編排形式。
那么我們先定義逐幀動畫xml文件
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
android:drawable="@drawable/pic1"
android:duration="200" />
android:drawable="@drawable/pic2"
android:duration="200" />
android:drawable="@drawable/pic3"
android:duration="200" />
android:drawable="@drawable/pic4"
android:duration="200" />
android:drawable="@drawable/pic5"
android:duration="200" />
android:drawable="@drawable/pic6"
android:duration="200" />
android:drawable="@drawable/pic7"
android:duration="200" />
android:drawable="@drawable/pic8"
android:duration="200" />
android:drawable="@drawable/pic8"
android:duration="200" />
main.xml
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="98dp"
android:layout_marginTop="69dp"
/>
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="54dp"
android:layout_marginLeft="98dp"
android:onClick="startMovie"
android:text="開始播放電影" />
Activiy代碼:
public class MyAnimationDemo extends Activity {
private AnimationDrawable draw=null;
private ImageView image;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_animation_demo);
image=(ImageView)super.findViewById(R.id.pic);
}
public void startMovie(View v){
image.setBackgroundResource(R.anim.oldvideo);//第一步,設置圖片資源
draw=(AnimationDrawable)image.getBackground();//取得圖片背景的Drawable
draw.setOneShot(false);//動畫執(zhí)行次數(shù)
draw.start();//開始動畫
}
}
這里我們看到,
第一步,設置圖片背景資源
第二步,設置得到圖片背景的draw
第三步,設置draw參數(shù),并start()
實現(xiàn)效果如下,間隔0.2秒即換圖,實現(xiàn)老電影動畫效果
以上就是Android 逐幀動畫的實例詳解,如有疑問請留言或到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
總結
以上是生活随笔為你收集整理的android 创建帧动画,Android 逐帧动画创建实例详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: css逐帧动画
- 下一篇: android 加载图片进度条,Imag