Android 帧动画使用简介
2015-03-23 10:42
148 查看
1. 帧动画
将多个图片放在一起,连续播放形成的动画,类似于GIF
2. 实现原理
把一张张图片按照顺序放入一个List(animation-list)中, 同时设置每个图片显示的时间长度,然后让其播放形成一个动画。
3. XML文件
在res/anim文件夹中创建一个anim_logo.xml的文件, 具体内容如下:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/ic_logo1" android:duration="500" />
<item android:drawable="@drawable/ic_logo2" android:duration="500" />
<item android:drawable="@drawable/ic_logo3" android:duration="500" />
<item android:drawable="@drawable/ic_logo4" android:duration="500" />
</animation-list>
每个item对应一个图片, android:duration可以设定该图片的显示时长。
android:oneshot
false : 循环播放
true: 播放一次
4. 调用动画
<ImageView
android:id="@+id/iv_click_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_status"
android:paddingLeft="15dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:background="@anim/anim_logo"
/>
5. 开始动画
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground();
anim.start();
6. 停止动画
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground();
anim.stop();
将多个图片放在一起,连续播放形成的动画,类似于GIF
2. 实现原理
把一张张图片按照顺序放入一个List(animation-list)中, 同时设置每个图片显示的时间长度,然后让其播放形成一个动画。
3. XML文件
在res/anim文件夹中创建一个anim_logo.xml的文件, 具体内容如下:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="@drawable/ic_logo1" android:duration="500" />
<item android:drawable="@drawable/ic_logo2" android:duration="500" />
<item android:drawable="@drawable/ic_logo3" android:duration="500" />
<item android:drawable="@drawable/ic_logo4" android:duration="500" />
</animation-list>
每个item对应一个图片, android:duration可以设定该图片的显示时长。
android:oneshot
false : 循环播放
true: 播放一次
4. 调用动画
<ImageView
android:id="@+id/iv_click_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_status"
android:paddingLeft="15dp"
android:layout_marginTop="15dp"
android:layout_centerHorizontal="true"
android:background="@anim/anim_logo"
/>
5. 开始动画
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground();
anim.start();
6. 停止动画
AnimationDrawable anim = (AnimationDrawable) mLogoImg.getBackground();
anim.stop();
相关文章推荐
- Android动画使用简介
- Android 动画使用详解(一) 帧动画
- Android 动画使用详解(二) 补间动画
- Android 动画使用详解(三) 属性动画
- Android学习-使用ViewFlipper实现屏幕切换的动画效果
- Android 动画的简单使用——视图动画
- Android 二维码的扫描,识别与生成功能使用简介
- android资源文件的使用(背景选择器,动画等)
- Android popupwindow动画的使用
- Android动画使用详解
- Android属性动画的使用(上)
- Android自定义控件7----滑动动画scrollTo/scrollBy使用
- Android各种动画使用
- android 属性动画用到的属性常量(方便使用
- Android中使用多张图片组成动画 AnimationDrawable
- Android中属性动画1----ObjectAnimator的基本使用(平移,缩放,渐变,旋转)
- Android中属性动画2----ObjectAnimator监听的使用
- android 学习使用Activity转场动画及shareElement
- Android中补间动画1----Animation的基本使用代码实现(平移,缩放,渐变,旋转)
- Android中补间动画2----Animation的基本使用代码实现复合使用