Frame动画就像放电影,一张张的播放
运行效果如下:
在Android中Frame动画的制作:
步骤:1.将要播放的图片复制到drawble文件夹下面
2.在drawble文件夹里面创建一个xml文件用于将图片加载进来
3.在Activity里面:得到一个AnimationDrawable对象,然后调用它的start()方法启动动画;
1.在drawble里的那个xml文件里面:
<?xml version="1.0" encoding="utf-8"?>
<!-- 创建一个animation-list用于将图片加载进来 -->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/tp1" android:duration="200"/>
<item android:drawable="@drawable/tp2" android:duration="200"/>
<item android:drawable="@drawable/tp3" android:duration="200"/>
<item android:drawable="@drawable/tp4" android:duration="200"/>
<item android:drawable="@drawable/tp5" android:duration="200"/>
<item android:drawable="@drawable/tp6" android:duration="200"/>
<item android:drawable="@drawable/tp7" android:duration="200"/>
</animation-list>
2.在Activity里面:
/**
* @author Cherry
* FrameByFrameAnimation的示例:
*/
public class FrameByFrameAnimationTestActivity extends Activity {
private ImageView imageView = null;
private Button button = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.frame_by_frame);
imageView = (ImageView)findViewById(R.id.imageView_id);
button = (Button)findViewById(R.id.button_id);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
imageView.setBackgroundResource(R.drawable.anim_tp);
AnimationDrawable animationDrawable = (AnimationDrawable)imageView.getBackground();
animationDrawable.start();
}
});
}
}