标签:
Frame Animation 表示帧动画,是顺序播放事先做好的图像,跟电影类似,Android SDK提供了另外一个类AnimationDrawable来定义使用Frame Animation。
下面我们就来看看具体怎么使用帧动画吧。
首先在drawable目录下新建一个frame.xml文件:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="@drawable/a"
android:duration="2000">
</item>
<item
android:drawable="@drawable/b"
android:duration="2000">
</item>
<item
android:drawable="@drawable/c"
android:duration="2000">
</item>
</animation-list>public void frameAnimation() throws FileNotFoundException {
TextView mTextView = (TextView) findViewById(R.id.tv);
mTextView.setBackgroundResource(R.drawable.frame);//把xml中设置好的帧动画资源设置给控件
AnimationDrawable animDrawable = (AnimationDrawable) mTextView
.getBackground();//得到该控件的背景Drawable对象
Bitmap bitmap = BitmapFactory
.decodeStream(new FileInputStream(Environment
.getExternalStorageDirectory() + "/Download/aaa.jpg"));//在代码中动态添加背景图,也可以从服务器获取到的输入流动态添加
animDrawable.addFrame(new BitmapDrawable(null, bitmap), 2000);//设置持续时间
animDrawable.setAlpha(180);//设置图片的透明度
animDrawable.setOneShot(false);//设置是否只运行一次,设置为true为循环运行
animDrawable.start();
}

标签:
原文地址:http://blog.csdn.net/u010687392/article/details/44133729