安卓(Android) 怎么实现抖动效果动画(Animation)

2019年10月16日21:58:18安卓(Android) 怎么实现抖动效果动画(Animation)已关闭评论 540 917字阅读3分3秒

1.简介

安卓(Android) 怎么实现抖动效果动画(Animation)?——请看下文。

2.示例代码

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


import android.view.View;

import android.view.animation.CycleInterpolator;

import android.view.animation.TranslateAnimation;

public class Main {

    public static final long DEFAULT_ANIMATION_DURATION = 1000;

    public static void shake(View view, float fromXDelta, float toXDelta,
            long durationMillis, float cycles) {
        translate(view, fromXDelta, toXDelta, 0.0f, 0.0f, durationMillis,
                cycles);
    }

    public static void shake(View view) {
        shake(view, 0.0f, 10.0f, DEFAULT_ANIMATION_DURATION, 7);
    }

    public static void translate(View view, float fromXDelta,
            float toXDelta, float fromYDelta, float toYDelta,
            long durationMillis, float cycles) {
        TranslateAnimation translateAnimation = new TranslateAnimation(
                fromXDelta, toXDelta, fromYDelta, toYDelta);
        translateAnimation.setDuration(durationMillis);
        if (cycles > 0.0) {
            translateAnimation
                    .setInterpolator(new CycleInterpolator(cycles));
        }
        view.startAnimation(translateAnimation);
    }
}

 
继续阅读
编程十万个怎么办