Android Animation --ScaleAnimation

来源:互联网 发布:军人网络保密准则 编辑:程序博客网 时间:2024/06/07 06:55

ScaleAnimation 缩放动画效果  是安卓中的动画效果之一
相关构造初始化方法 ScaleAnimation scale =new 

ScaleAnimation(Context context, AttributeSet attrs)  从XML文件加载动画,基本用不到ScaleAnimation(float fromX, float toX, float fromY, float toY)ScaleAnimation(float fromX, float toX, float fromY, float toY, float pivotX, float pivotY)ScaleAnimation(float fromX, float toX, float fromY, float toY, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
ScaleAnimation(float fromX, float toX, float fromY, float toY,int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)</span>


float fromX 动画起始时 X坐标上的伸缩尺寸 float toX 动画结束时 X坐标上的伸缩尺寸 float fromY 动画起始时Y坐标上的伸缩尺寸 float toY 动画结束时Y坐标上的伸缩尺寸 int pivotXType 动画在X轴相对于物件位置类型 float pivotXValue 动画相对于物件的X坐标的开始位置 int pivotYType 动画在Y轴相对于物件位置类型 float pivotYValue 动画相对于物件的Y坐标的开始位置 


相关的设置 

ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 1.0f, 1.0f,                Animation.RELATIVE_TO_SELF, 0.5f,                Animation.RELATIVE_TO_SELF, 1.0f);        //逐渐加速进入的动画 先慢后快//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.accelerate_interpolator));//        ////加速进入.与第一个的区别为当repeatMode为reverse时,仍为加速返回原点//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.accelerate_decelerate_interpolator));        //先向后退一点再加速前进//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.anticipate_interpolator));//        //减速前进  冲过终点后再后退//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.overshoot_interpolator));        ////先往后退一点再加速前进   再减速超过一点再后退//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.anticipate_overshoot_interpolator));        //停止下来回振几次        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,                android.R.anim.bounce_interpolator));        //逐渐减速进入的动画  先快后慢//        scaleAnimation.setInterpolator(AnimationUtils.loadInterpolator(this,//                android.R.anim.decelerate_interpolator));        //设置动画启动的延时时间        scaleAnimation.setStartOffset(300);        //设置动画执行的时间        scaleAnimation.setDuration(2000);        //设置重复的次数        scaleAnimation.setRepeatCount(Integer.MAX_VALUE);//        //设置执行的模式 RESTART为结束后重新开始,//        scaleAnimation.setRepeatMode(Animation.RESTART);//        //设置执行的模式为按原来的轨迹逆向返回        scaleAnimation.setRepeatMode(Animation.REVERSE);//        scaleAnimation.setRepeatMode(Animation.START_ON_FIRST_FRAME);//        scaleAnimation.setRepeatMode(Animation.ZORDER_BOTTOM);//        scaleAnimation.setRepeatMode(Animation.ZORDER_NORMAL);//        scaleAnimation.setRepeatMode(Animation.ZORDER_TOP);        //绝对位置//        scaleAnimation.setRepeatMode(Animation.ABSOLUTE);        //无限循环//        scaleAnimation.setRepeatMode(Animation.INFINITE);        //相对于父控件//        scaleAnimation.setRepeatMode(Animation.RELATIVE_TO_PARENT);        //相对于本身//        scaleAnimation.setRepeatMode(Animation.RELATIVE_TO_SELF);        AnimationSet animationSet = new AnimationSet(true);        animationSet.addAnimation(alphaAnimation1);        animationSet.addAnimation(scaleAnimation);        mTvTitleBackground.startAnimation(scaleAnimation);
</pre><pre name="code" class="html">
XML中的定义方式  
<pre name="code" class="html"><?xml version="1.0" encoding="utf-8"?><scale xmlns:android="http://schemas.android.com/apk/res/android"    android:fromXScale="1.0"    android:toXScale="0.0"    android:fromYScale="1.0"    android:toYScale="0.0"    android:pivotX="50%"    android:pivotY="50%"    android:fillAfter="true"    android:duration="400"    ></scale>






0 0