Android 动画总结

1.补间动画 View Animation(Tween Animation)1.1位移动画xml定义:<translate xmlns:android=""android:fromXDelta="0"android:toXDelta="300"android:fromYDelta="100%p"android:toYDelta="0"android:duration="200"/> <!–fromXDelta 动画起始位置的横坐标 toXDelta 动画起结束位置的横坐标 fromYDelta 动画起始位置的纵坐标 toYDelta 动画结束位置的纵坐标 duration 动画的持续时间 100%p 表示自身的长度的位置 –> 代码实现:Animation animation = new TranslateAnimation(0,50,0,50);参数1:x轴的起始位置参数2:x轴的终止位置参数3: y轴的起始位置参数4:y轴的终止位置相对于原图位置的原点(图片的右上角为0,0),如果不想用这个点作为参照点,可以使用其他构造TranslateAnimation(fromXType, fromXValue, toXType, toXValue, fromYType, fromYValue, toYType, toYValue)参数1,参数3,参数5,参数7就是设置参照点的方式1.2旋转动画xml定义:<rotate xmlns:android=""android:fromDegrees="0"android:toDegrees="360"android:duration="200" /> <!–fromDegrees:表示旋转的起始角度 toDegrees:表示旋转的结束角度 duration 动画的持续时间 from<to:顺时针旋转 from>to:逆时针旋转 –> 代码实现:Animation animation = new RotateAnimation(360,0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 参数1:旋转的起始角度参数2:旋转的终止角度参数3:旋转中心的x轴取值参照方式参数4:中心点x轴的取值参数5:旋转中心的y轴取值参照方式参数6:中心点y轴的取值1.3透明度动画xml定义:<alpha xmlns:android=""android:fromAlpha="1.0"android:toAlpha="0.1"android:duration="200"/> <!–fromAlpha :起始透明度 toAlpha:结束透明度 1.0表示完全不透明 0.0表示完全透明 –> 代码实现:Animation animation = new AlphaAnimation(1f,0.1f);参数1: 起始透明度;参数2: 目标透明度;1.4缩放动画xml定义:<scale xmlns:android=""android:fromXScale="0.5"android:toXScale="1.0"android:fromYScale="0.5"android:toYScale="1.0"android:pivotX="50%"android:pivotY="50%"android:duration="200"/> <!–fromXScale:表示沿着x轴缩放的起始比例 toXScale:表示沿着x轴缩放的结束比例 fromYScale:表示沿着y轴缩放的起始比例 toYScale:表示沿着y轴缩放的结束比例 1.0表示原来的大小 50%表示图片中心点 –> 代码实现:Animation animation = new ScaleAnimation(1f,0.2f,1f,0.2f,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); 参数1:x方向起始大小(1f表示原图大小)参数2:x方向终止大小(0.2f表示原图的0.2倍)参数3:y方向起始大小(1f表示原图大小)参数4:y方向终止大小(0.2f表示原图的0.2倍)参数5:缩放中心点x轴取值的参照方式参数6:中心点x轴的取值(0.5f表示相对与原图的0.5倍)参数7:缩放中心点y轴取值参照方式参数8:中心点y轴的取值(0.5f表示相对与原图的0.5倍)(注:参照方式:Animation.RELATIVE_TO_SELF:自身 Animation.RELATIVE_TO_PARENT:父控件 Animation.ABSOLUTE:绝对)1.5 共有属性android:duration(播放时间)android:repeatCount: 重复的次数 默认值是0 代表旋转1次,值为-1或者infinite时,表示动画永不停止 android:repeatMode: 设置重复的模式。默认是restart。(当repeatCount的值大于0或者为infinite时才有效)设成reverse,表示偶数次显示动画时会做与动画文件定义的方向相反的方向动行。 对应代码方法:Animation.setDuration(long durationMillis)Animation.setRepeatCount(int repeatCount)Animation.setRepeatMode(int repeatMode)android:interpolator(动画的渲染器) accelerate_interpolator(动画加速器) 使动画在开始的时候 最慢,然后逐渐加速 decelerate_interpolator(动画减速器) 使动画在开始的时候 最快,然后逐渐减速 accelerate_decelerate_interpolator(动画加速减速器)慢到快(中间位置最快)到慢 anticipate_interpolator(动画前反向器) 先往动画移动的反方向移动一点然后在沿着设定的动画移动 overshoot_interpolator(动画后反向器) 最后超出目的值然后缓慢改变到目的值 anticipate_overshoot_interpolator (动画双反向器) 先往动画的反方向移动一点,然后沿着设定的方向移动到终点之后继续移动一点然后在回弹到最终设定的位置 bounce_interpolator(动画弹跳器) 快到目的值时值会跳跃 cycle_interpolator(动画循环器) 动画循环一定次数 linear_interpolator(动画匀速器) 线性均匀改变 overshoot_interpolator(动画减速器) 快速到达终点并超出一小步最后回到终点 使用:android:interpolator="@android:anim/accelerate_interpolator"对应代码方法:Animation.setInterpolator(Context context, int resID) //R.anim.accelerate_interpolatorAnimation.setInterpolator(Interpolator i) TimeInterpolator          一个接口,允许你自定义interpolator,以下几个都是实现了这个接口 AccelerateInterpolator      加速,开始时慢中间加速 DecelerateInterpolator       减速,开始时快然后减速 AccelerateDecelerateInterolator  先加速后减速,开始结束时慢,中间加速 AnticipateInterpolator       反向 ,先向相反方向改变一段再加速播放 AnticipateOvershootInterpolator  反向加超越,先向相反方向改变,再加速播放,会超出目的值然后缓慢移动至目的值 BounceInterpolator        跳跃,快到目的值时值会跳跃,如目的值100,后面的值可能依次为85,77,,70,80,90,100 CycleInterpolator          循环,动画循环一定次数,值的改变为一正弦函数:Math.sin(2 * mCycles * Math.PI * input) LinearInterpolator         线性,线性均匀改变 OvershottInterpolator       超越,最后超出目的值然后缓慢改变到目的值2.组合动画2.1AnimationSetxml定义:<set xmlns:android=""android:interpolator="@android:anim/accelerate_decelerate_interpolator"android:shareInterpolator="true" ><scale … /><rotate … /><translate … /><alpha … /> <!–shareInterpolator:里面动画效果是否共享一个Interpolator 不共享设置android:shareInterpolator="false",每一个动画效果自己添加interpolator。 –></set> 代码实现:AlphaAnimation alpha=new AlphaAnimation(0, 1); alpha.setDuration(1000); AnimationSet animSet = new AnimationSet(false);animSet.addAnimation(alpha);2.2 LayoutAnimation(GridLayoutAnimationController)更有一种逍遥,浑然忘我,与大自然交融的境界令人心弛神往。

Android 动画总结

相关文章:

你感兴趣的文章:

标签云: