您的位置:首页 > 其它

帧动画

2016-06-14 16:10 92 查看
动画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...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: