安卓(Android) 怎么将目标对象从其中心向两边缩放,直到从给定对象达到给定值为止

2019年10月15日21:32:04安卓(Android) 怎么将目标对象从其中心向两边缩放,直到从给定对象达到给定值为止已关闭评论 194 2227字阅读7分25秒

1.简介

安卓(Android) 怎么将目标对象从其中心向两边缩放,直到从给定对象达到给定值为止?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */


import android.view.View;

import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

import android.view.animation.Interpolator;
import android.view.animation.ScaleAnimation;

public class Main {
    
     
    public static void StartScale(View target, float from, float to,
            int duration) {
        target.clearAnimation();
        target.startAnimation(Scale(from, to, duration));
    }

    
    public static void StartScale(View target, float from, float to,
            int duration, Interpolator interpolation) {
        target.clearAnimation();
        target.startAnimation(Scale(from, to, duration, interpolation));
    }

    
    public static void StartScale(View target, float from, float to,
            int duration, Interpolator interpolation,
            AnimationListener listener) {
        target.clearAnimation();
        target.startAnimation(Scale(from, to, duration, interpolation,
                listener));
    }

    
    public static void StartScale(View target, float fromX, float toX,
            float fromY, float toY, int pivotXType, float pivotXValue,
            int pivotYType, float pivotYValue, int duration,
            Interpolator interpolation, AnimationListener listener) {
        target.clearAnimation();
        target.startAnimation(Scale(fromX, toX, fromY, toY, pivotXType,
                pivotXValue, pivotYType, pivotYValue, duration,
                interpolation, listener));
    }

    
    public static Animation Scale(float from, float to, int duration) {
        return Scale(from, to, duration, null);
    }

    
    public static Animation Scale(float from, float to, int duration,
            Interpolator interpolation) {
        return Scale(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f, duration, interpolation,
                null);
    }

    
    public static Animation Scale(float from, float to, int duration,
            Interpolator interpolation, AnimationListener listener) {
        return Scale(from, to, from, to, Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f, duration, interpolation,
                listener);
    }

    
    public static Animation Scale(float fromX, float toX, float fromY,
            float toY, int pivotXType, float pivotXValue, int pivotYType,
            float pivotYValue, int duration, Interpolator interpolation,
            AnimationListener listener) {
        ScaleAnimation animation = new ScaleAnimation(fromX, toX, fromY,
                toY, pivotXType, pivotXValue, pivotYType, pivotYValue);
        animation.setDuration(duration);

        if (interpolation != null)
            animation.setInterpolator(interpolation);

        if (listener != null) {
            animation.setAnimationListener(listener);
        }

        return animation;
    }
}

 
继续阅读