帧动画

来源:互联网 发布:python json 美化输出 编辑:程序博客网 时间:2024/06/15 16:51

动画anima.xml文件(在drawable目录下):
oneshot表示执行次数,当为false时则表示只执行一次,当为true时表示循环执行

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"android:oneshot="false">    <item android:drawable="@drawable/pic_1 android:duration="200"/>    <item android:drawable="@drawable/pic_2 android:duration="200"/>    <item android:drawable="@drawable/pic_3 android:duration="200"/>    <item android:drawable="@drawable/pic_4 android:duration="200"/></animation>

布局文件:

<LinearLayout    xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent">    <ImageView        android:id="@+id/iv_test"        android:layout_width="wrap_content"        android:layout_height="wrap_content"/></LinearLayout>

java代码:

...code..    ImageView ivTest = (ImageView)findViewById(R.id.iv_test);    ivTest.setBackgroundResource(R.drawable.anima);    AnimationDrawable ad = (AnimationDrawable)ivTest.getBackground();//获取帧动画对象    ad.start();....code...
0 0
原创粉丝点击