Android中常用的动画包括属性动画,帧动画(frameAnimation),补间动画(Tween);
属性动画:AnimationSet,AlphaAnimation,RotateAnimation,ScaleAnimation
帧动画:一组图片的浏览
Tween:用的比较少,没有真真改变图片的位置,而属性动画改变了
帧动画的使用:
1.drawable下建一个xml文件
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true"
>
<item android:drawable="@drawable/a" android:duration="1000"></item>
<item android:drawable="@drawable/b" android:duration="1000"></item>
<item android:drawable="@drawable/c" android:duration="1000"></item>
<item android:drawable="@drawable/d" android:duration="1000"></item>
<item android:drawable="@drawable/e" android:duration="1000"></item>
</animation-list>
说明:1.默认情况下会一直播放,oneShot后只播放一次
<span style="white-space:pre"> </span>2.需要添加的条件:图片,持续的时间
2.找到图片控件,通过设置背景将Animation—list添加,并开始;注意有的时候需要执行条件
if(drawable.isRunning())(drawable.stop();drawable.start())
<pre name="code" class="html"> iv = (ImageView) findViewById(R.id.iv);
iv.setImageResource(R.drawable.test);
AnimationDrawable drawable= (AnimationDrawable) iv.getDrawable();
drawable.start();
属性动画
<span style="font-size:12px;"> AnimationSet animationSet = new AnimationSet(false);
AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
alphaAnimation.setDuration(300);
alphaAnimation.setFillAfter(true);
RotateAnimation rotateAnimation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
rotateAnimation.setDuration(300);
rotateAnimation.setFillAfter(true);
//缩放动画
ScaleAnimation scaleAnimation = new ScaleAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
scaleAnimation.setFillAfter(true);
scaleAnimation.setDuration(300);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(rotateAnimation);
animationSet.addAnimation(scaleAnimation);