Android自助餐之动画(一)帧动画

来源:互联网 发布:daogrs知乎 编辑:程序博客网 时间:2024/05/20 11:51

Android自助餐之动画(一)帧动画

  • Android自助餐之动画一帧动画
      • 查看全套目录
      • 下载完整源代码
    • 准备动画所需图片
    • 编写amin的xml文件
    • 把amin设置到ImageView上
    • 需要开始动画的地方作如下处理

查看全套目录

下载完整源代码

准备动画所需图片

此处已准备四张图片放到drawable-xxhdpi下,分别为pic1、pic2、pic3、pic4

编写amin的xml文件

google官方建议这种动画xml放到drawable下管理

<?xml version="1.0" encoding="utf-8"?><animation-list xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/pic1" android:duration="200"/>    <item android:drawable="@drawable/pic2" android:duration="200"/>    <item android:drawable="@drawable/pic3" android:duration="200"/>    <item android:drawable="@drawable/pic4" android:duration="200"/></animation-list>

把amin设置到ImageView上

写到background上,便于在java中获取

<ImageView    android:id="@+id/iamge"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:layout_centerInParent="true"    android:background="@drawable/animation"    />

需要开始动画的地方作如下处理

AnimationDrawable animationXml = (AnimationDrawable) image.getBackground();animationXml.start();
0 0
原创粉丝点击