首页 > 移动平台 > 详细

android帧动画

时间:2016-03-04 00:31:05      阅读:345      评论:0      收藏:0      [点我收藏+]

一、在xml文件中设置帧动画

1、首先得在drawable资源文件夹下创建一个animation_list文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@drawable/p1"
        android:duration="500" />
    <item
        android:drawable="@drawable/p2"
        android:duration="500" />
    <item
        android:drawable="@drawable/p3"
        android:duration="500" />
    <item
        android:drawable="@drawable/p4"
        android:duration="500" />
    <item
        android:drawable="@drawable/p5"
        android:duration="500" />

</animation-list>

2、通过java代码启动将动画加载到空间中,并启动

ImageView imageView=(ImageView)findViewById(R.id.id_iv);
imageView.setImageResource(R.drawable.anim_list);
AnimationDrawable animationDrawable = (AnimationDrawable) image.getDrawable();
animationDrawable.setOneShot(false);//是否只执行一次
animationDrawable.start();//开启动画
//animationDrawable.stop();//停止动画

  

二、在java代码中设置帧动画

ImageView imageView= (ImageView)findViewById(R.id.id_iv);
animationDrawable= new AnimationDrawable();
animationDrawable.addFrame(getResources().getDrawable(R.drawable.p1), 500);
animationDrawable.addFrame(getResources().getDrawable(R.drawable.p2), 500);
imageView.setImageDrawable(animationDrawalbe);
animationDrawable.setOneShot(false);//是否只执行一次
animationDrawable.start();//开启动画
//animationDrawable.stop();//停止动画

  

  

  

android帧动画

原文:http://www.cnblogs.com/zhisuoyu/p/5240546.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!