Android动画之Drawable Animation
2014-10-17 13:58
561 查看
Drawable Animation 的 XML文件放在 /res/drawable目录下,它只将一些drawable元素放在一个容器当中,指定每一个drawable元素的属性,然后一帧一帧地播放出来。
创建如下的动画文件/res/drawable/rocket_thrust.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>每一个item就是动画的一帧,并且可以指定这一帧动画的duration, 因为它在/res/drawable目录下,所以,可以把它设定到一些组件的背景。
AnimationDrawable rocketAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);//将动画设定到rocketImage的背景
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();//强转为AnimationDrawable类型
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {//点击时,启动动画
rocketAnimation.start();
return true;
}
return super.onTouchEvent(event);
}
通过drawable animation可以方便地实现类型于gif动画图的效果
创建如下的动画文件/res/drawable/rocket_thrust.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/rocket_thrust1" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
<item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>每一个item就是动画的一帧,并且可以指定这一帧动画的duration, 因为它在/res/drawable目录下,所以,可以把它设定到一些组件的背景。
AnimationDrawable rocketAnimation;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);//将动画设定到rocketImage的背景
rocketAnimation = (AnimationDrawable) rocketImage.getBackground();//强转为AnimationDrawable类型
}
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {//点击时,启动动画
rocketAnimation.start();
return true;
}
return super.onTouchEvent(event);
}
通过drawable animation可以方便地实现类型于gif动画图的效果
相关文章推荐
- Android动画 之 FrameAnimation(AnimationDrawable)
- android之动画通过AnimationDrawable控制逐帧动画
- Android 动画系列一:Drawable Animation
- Android 编程下 AnimationDrawable (动画)的实现
- Android(java)学习笔记198:Android下的帧动画(Drawable Animation)
- Android绘图动画---Drawable Animation
- Android应用通过AnimationDrawable实现View的动画效果
- android frame by frame AnimationDrawable 实现动画效果
- Android 动画详解之Frame动画 (Drawable Animation)
- android动画之帧动画(drawable animation)和补间动画(view animation)
- Android应用开发——Animation Drawable ImageView显示动画
- Android开发者指南-Drawable 动画-Drawable Animation[原创译文]
- android之动画(一)通过AnimationDrawable控制逐帧动画
- Android 动画具体解释Frame动画 (Drawable Animation)
- Android图片动画播放(AnimationDrawable)
- Android 编程下 AnimationDrawable (动画)的实现
- Android学习篇章17-动画1Frame动画AnimationDrawable
- android之动画(一)通过AnimationDrawable控制逐帧动画
- Android 动画之一 Drawable Animation —— 逐帧(Frame)动画
- Android AnimationDrawable动画与APP启动引导页面