Android学习笔记进阶十一图片动画播放(AnimationDrawable)
来源:互联网 发布:淘宝买家怎么申请退款 编辑:程序博客网 时间:2024/04/29 14:29
大家平时见到的最多的可能就是Frame动画了,Android中当然也少不了它。它的使用更加简单,只需要创建一个
AnimationDrawabledF对象来表示Frame动画,然后通过addFrame 方法把每一帧要显示的内容添加进去,并设置播放间隔时间,本例子中间隔时间为5S,
最后通过start 方法就可。
以播放这个动画了,同时还可以通过 setOneShot方法设置是否重复播放。
- package xiaosi.bu;
- import android.app.Activity;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.widget.Button;
- import android.widget.ImageView;
- public class TupianActivity extends Activity {
- /** Called when the activity is first created. */
- private Button start = null;
- private Button stop = null;
- private ImageView image = null;
- private AnimationDrawable animationDrawable = null;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- start = (Button)findViewById(R.id.start);
- start.setOnClickListener(new StartListener());
- stop = (Button)findViewById(R.id.stop);
- stop.setOnClickListener(new StopListener());
- image = (ImageView)findViewById(R.id.imageview);
- animationDrawable = new AnimationDrawable();
- for(int i =0;i<8;i++){
- //第一个 就是我们的资源名称(图片名)
- //第二个 就是我们存放图片的文件夹drawable
- //第三个 包名也可以用Context的getPackageName返回应用程序的包名
- int id = getResources().getIdentifier( "a"+i, "drawable", "xiaosi.bu");
- System.out.println("ID:" + id);
- animationDrawable.addFrame(getResources().getDrawable(id), 2000);
- }
- //设置手否重复播放,false为重复
- animationDrawable.setOneShot(false);
- image.setImageDrawable(animationDrawable);
- }
- private class StartListener implements OnClickListener{
- public void onClick(View v)
- {
- animationDrawable.start();
- }
- }
- private class StopListener implements OnClickListener{
- public void onClick(View v)
- {
- animationDrawable.stop();
- }
- }
- }
main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <LinearLayout
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- <Button android:id="@+id/start"
- android:text="Start"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- <Button android:id="@+id/stop"
- android:text="End"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"/>
- </LinearLayout>
- <ImageView android:id="@+id/imageview"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:scaleType="fitXY"
- android:background="#ffffff" />
- </LinearLayout>
原文地址:http://blog.csdn.net/sjf0115/article/details/7265307
源代码:点击打开链接
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- Android图片动画播放(AnimationDrawable)
- 图片动画播放(AnimationDrawable)
- AnimationDrawable android 动画 初始化界面播放
- Android中的AnimationDrawable(图片动画)介绍及使用
- AnimationDrawable 播放动画需要注意
- android AnimationDrawable动画
- Android学习篇章17-动画1Frame动画AnimationDrawable
- Android中使用多张图片组成动画 AnimationDrawable
- Android中使用多张图片组成动画 AnimationDrawable
- Android动画 - AnimationDrawable帧动画
- 自定义AnimationDrawable动画播放完监听
- Android动画 之 FrameAnimation(AnimationDrawable)
- Android学习笔记(十一)
- Android使用SurfaceView代替AnimationDrawable播放多图帧动画,避免OOM和卡顿
- 上传图片---SpringMVC学习笔记(十一)
- 上传图片---SpringMVC学习笔记(十一)
- 加载模型
- C枚举类型的使用方法
- HDU 1065 || ZOJ 1049 I Think I Need a Houseboat
- 材质纹理
- Little Elephant and Function
- Android学习笔记进阶十一图片动画播放(AnimationDrawable)
- EGL intro 概述
- Little Elephant and Problem
- OpenGL ES 概述
- 编程必备*错误异常信息记录工具—log4j使用方法
- IDIOPEN 2011 G - Sleeping at Work
- C++面试题:介绍一下STL,STL如何实现vector
- linux动静态库的创建及使用
- Android动画背景图自动播放的实现