public class DAActivity extends Activity implements OnClickListener {

    private ImageView iv_da_mm;
    private Button btn_da_start;
    private Button btn_da_stop;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animation_da);
        iv_da_mm = (ImageView) findViewById(R.id.iv_da_mm);
        btn_da_start = (Button) findViewById(R.id.btn_da_start);
        btn_da_stop = (Button) findViewById(R.id.btn_da_stop);

        btn_da_start.setOnClickListener(this);
        btn_da_stop.setOnClickListener(this);
    }

    private AnimationDrawable animationDrawable;
    @Override
    public void onClick(View v) {
        if (v == btn_da_start) {
            if(animationDrawable==null) {
                //得到背景动画图片对象
                animationDrawable = (AnimationDrawable) iv_da_mm.getBackground();
                //启动
                animationDrawable.start();
            }

        } else if (v == btn_da_stop) {
            if(animationDrawable!=null) {
                animationDrawable.stop();
                animationDrawable = null;
            }
        }
    }
}


drawable_animation_test.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/nv1"
        android:duration="500"/>
    <item
        android:drawable="@drawable/nv2"
        android:duration="500"/>
    <item
        android:drawable="@drawable/nv3"
        android:duration="500"/>
    <item
        android:drawable="@drawable/nv4"
        android:duration="500">
    </item>

</animation-list>

activity_animation_da.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/iv_da_mm"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="160dp"
        android:background="@drawable/drawable_animation_test"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true" >

        <Button
            android:id="@+id/btn_da_start"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="启动动画" />

        <Button
            android:id="@+id/btn_da_stop"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="结束动画" />
    </LinearLayout>

</RelativeLayout>

测试drawable animation的更多相关文章

  1. 动画的使用—Drawable Animation

    Drawable Animation可以称为帧动画,因为它是通过每次播放一帧Drawable资源实现的. Drawable Animation算不上真正意义上的动画,因为它的内部实现是通过定时发送消息 ...

  2. Android动画Drawable Animation

    Drawable Animation是逐帧动画,那么使用它之前必须先定义好各个帧.我们可以通过代码定义,也可以使用xml文件定义,一般使用后者.如下: <?xml version="1 ...

  3. Android动画主要包含补间动画(Tween)View Animation、帧动画(Frame)Drawable Animation、以及属性动画Property Animation

    程序运行效果图: Android动画主要包含补间动画(Tween)View Animation.帧动画(Frame)Drawable Animation.以及属性动画Property Animatio ...

  4. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  5. Android animation学习笔记之view/drawable animation

    前一章中总结了android animation中property animation的知识和用法,这一章总结View animation和Drawable animation的有关知识: View ...

  6. 动画的使用—Drawable Animation

    Drawable Animation可以称为帧动画,因为它是通过每次播放一帧Drawable资源实现的. Drawable Animation算不上真正意义上的动画,因为它的内部实现是通过定时发送消息 ...

  7. 【Android界面实现】Drawable Animation 使用介绍

        转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992     (眼下仅仅能用在View对象上的动画效果的实现有两种,一种就是上一篇的View Animat ...

  8. Android动画View Animation与Drawable Animation

    Animations 一.Animations介绍 Animations是一个实现android UI界面动画效果的API,Animations提供了一系列的动画效果,可以进行旋转.缩放.淡入淡出等, ...

  9. drawable animation

    drawable 动画,帧动画: 1 定义动画xml文件 <?xml version="1.0" encoding="utf-8"?> <an ...

随机推荐

  1. FORM标准默认时间区间处理

    WHEN-NEW-FORM-INSTANCE DECLARE    temp_date         date;    client_timezone   date;    char_date    ...

  2. 查询执行慢的SQL

    --执行慢的SQL: SELECT S.SQL_TEXT, S.SQL_FULLTEXT, S.SQL_ID, ROUND(ELAPSED_TIME / 1000000 / (CASE WHEN (E ...

  3. context:exclude-filter spring事宜【经典-转】

    context:exclude-filter spring事务 如果带上事务,那么用annotation方式的事务注解和bean配置,事务会失效,要将service bean配置到xml文件中才行. ...

  4. 转: maven打可执行的jar包以及classpath设置

    from:  http://drizzlewalk.blog.51cto.com/2203401/416508

  5. 开源 免费 java CMS - FreeCMS2.1 会员我的留言

    项目地址:http://www.freeteam.cn/ 我的留言 从左側管理菜单点击我的留言进入.在这里能够查看当前登录会员的全部留言记录. 查看留言 点击留言标题能够查看留言具体内容. 删除留言 ...

  6. HTTP学习笔记(一)报文和连接管理

    对TCP/IP协议簇有些了解的同学们应该都知道.TCP/IP协议通过精简ISO网络7层协议(事实上了解历史渊源的话,TCP/IP协议本来目的并非简化ISO的7层协议.仅仅是因为ISO协议簇制定速度慢于 ...

  7. Java集合框架GS Collections具体解释

    Java集合框架GS Collections具体解释 作者:chszs.未经博主同意不得转载.经许可的转载需注明作者和博客主页:http://blog.csdn.net/chszs GS Collec ...

  8. zabbix agent shell一键安装脚本

    #!/bin/bash basepath=$(cd ``; pwd) SHELL_DIR="${basepath}/shell" PACKAGE_DIR="${basep ...

  9. Python Flask 在Sina App Engine (SAE)上安家

    早就听说了Python的大名,随着的编程语言的理解加深,越发认为动态语言的威力--真大呀. 趁这段时间不忙,我也用Python写了一个应用,而且将其部署到Sina App Engine (SAE).S ...

  10. Centos6.0使用第三方YUM源(EPEL,RPMForge,RPMFusion)

    yum是centos下很方便的rpm包管理工具,配置第三方软件库使你的软件库更加丰富.以下简单的讲下配置的步骤. 首先,需要安装yum-priorities插件: yum install yum-pr ...