AnimationDrawable和逐帧动画
来源:互联网 发布:武汉包年网络推广 编辑:程序博客网 时间:2024/04/29 13:18
获取 AnimationDrawable对象之后,接下来就可用把 AnimationDrawable显示出来,—–习惯上把AnimationDrawable设为ImageView的背景即可.
需要注意的是 AnimationDrawable代表的动画默认是不播放的.必须在程序中启动动画播放才可以.AnimationDrawable 提供了两个方法() : 开始停止动画.
- start( ): 开始播放动画.
- stop( ): 停止播放动画.
package com.test.frameanimation;import android.graphics.drawable.AnimationDrawable;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.Button;import android.widget.ImageView;/** * 帧动画 AnimationDrawable */public class MainActivity extends AppCompatActivity { Button play, stop; ImageView image; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); play = (Button) findViewById(R.id.btn_start); stop = (Button) findViewById(R.id.btn_stop); image = (ImageView) findViewById(R.id.id_image); //获取 AnimationDrawable 对象 final AnimationDrawable anim = (AnimationDrawable) image.getBackground(); play.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { anim.start(); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { anim.stop(); } }); }}
布局文件
<?xml version="1.0" encoding="utf-8"?><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" android:orientation="vertical" tools:context="com.test.frameanimation.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center" > <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="开始动画"/> <Button android:id="@+id/btn_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="停止动画"/> </LinearLayout> <ImageView android:layout_gravity="center" android:id="@+id/id_image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@anim/fat_panda" android:scaleType="fitXY" /></LinearLayout>
动画资源文件
<?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/fat_po_f01" android:duration="160"/> <item android:drawable="@drawable/fat_po_f02" android:duration="60"/> <item android:drawable="@drawable/fat_po_f03" android:duration="160"/> <item android:drawable="@drawable/fat_po_f04" android:duration="60"/> <item android:drawable="@drawable/fat_po_f05" android:duration="60"/> <item android:drawable="@drawable/fat_po_f06" android:duration="160"/> <item android:drawable="@drawable/fat_po_f07" android:duration="160"/> <item android:drawable="@drawable/fat_po_f08" android:duration="160"/> <item android:drawable="@drawable/fat_po_f09" android:duration="160"/> <item android:drawable="@drawable/fat_po_f10" android:duration="160"/> <item android:drawable="@drawable/fat_po_f11" android:duration="160"/> <item android:drawable="@drawable/fat_po_f12" android:duration="160"/> <item android:drawable="@drawable/fat_po_f13" android:duration="160"/> <item android:drawable="@drawable/fat_po_f14" android:duration="160"/> <item android:drawable="@drawable/fat_po_f15" android:duration="160"/> <item android:drawable="@drawable/fat_po_f16" android:duration="160"/> <item android:drawable="@drawable/fat_po_f17" android:duration="160"/> <item android:drawable="@drawable/fat_po_f18" android:duration="160"/> <item android:drawable="@drawable/fat_po_f19" android:duration="160"/> <item android:drawable="@drawable/fat_po_f20" android:duration="160"/> <item android:drawable="@drawable/fat_po_f21" android:duration="160"/> <item android:drawable="@drawable/fat_po_f22" android:duration="160"/> <item android:drawable="@drawable/fat_po_f23" android:duration="160"/> <item android:drawable="@drawable/fat_po_f24" android:duration="160"/> <item android:drawable="@drawable/fat_po_f25" android:duration="160"/> <item android:drawable="@drawable/fat_po_f26" android:duration="160"/> <item android:drawable="@drawable/fat_po_f27" android:duration="160"/></animation-list>
0 0
- AnimationDrawable和逐帧动画
- 逐帧动画 AnimationDrawable
- AnimationDrawable与逐帧动画
- AnimationDrawable(通过AnimationDrawable控制逐帧动画)
- 动画 AnimationDrawable 帧动画
- AnimationDrawable逐帧动画--爆炸效果
- Android AnimationDrawable与逐帧动画
- Android动画 - AnimationDrawable帧动画
- android之动画通过AnimationDrawable控制逐帧动画
- android之动画-AnimationDrawable控制逐帧动画
- Android自定义控件:动画类---逐帧动画AnimationDrawable
- android动画 通过AnimationDrawable控制逐帧动画
- AnimationDrawable 帧动画 爆炸特效
- Android 逐帧动画AnimationDrawable 内存溢出的一个解决方法
- 安卓 AnimationDrawable 逐帧动画的使用
- android动画之 FrameAnimation(帧动画) AnimationDrawable
- 安卓动画 - 帧动画AnimationDrawable
- 帧动画以及AnimationDrawable的使用
- iOS 归档(NSKeyedArchiver + NSCoding)
- 2.4 死锁
- 模拟小结
- php内存管理简介
- android TabHost导航切换实现方式
- AnimationDrawable和逐帧动画
- 类加载器
- 暴力小结
- 安装sublime
- ultraedit正则表达式
- 数字每三位加逗号的方法
- 【C/C++】:函数返回结构体的写法
- 第一篇iOS博客
- From detailed models to formal spiking neurons