/**
* 动画抖动效果
* @param view 抖动控件
* @param scaleLarge 缩小倍数
* @param shakeDegrees 放大倍数
* @param duration 抖动角度
* @param isInfinite 是否循环抖动
*/
private void startShakeByPropertyAnim(View view, float scaleSmall, float scaleLarge, float shakeDegrees, long duration,boolean isInfinite) {
if (view == null) {
return;
}
PropertyValuesHolder scaleXValuesHolder = PropertyValuesHolder.ofKeyframe(View.SCALE_X,
Keyframe.ofFloat(0f, 1.0f),
Keyframe.ofFloat(0.25f, scaleSmall),
Keyframe.ofFloat(0.5f, scaleLarge),
Keyframe.ofFloat(0.75f, scaleLarge),
Keyframe.ofFloat(1.0f, 1.0f)
);
PropertyValuesHolder scaleYValuesHolder = PropertyValuesHolder.ofKeyframe(View.SCALE_Y,
Keyframe.ofFloat(0f, 1.0f),
Keyframe.ofFloat(0.25f, scaleSmall),
Keyframe.ofFloat(0.5f, scaleLarge),
Keyframe.ofFloat(0.75f, scaleLarge),
Keyframe.ofFloat(1.0f, 1.0f)
);
PropertyValuesHolder rotateValuesHolder = PropertyValuesHolder.ofKeyframe(View.ROTATION,
Keyframe.ofFloat(0f, 0f),
Keyframe.ofFloat(0.1f, -shakeDegrees),
Keyframe.ofFloat(0.2f, shakeDegrees),
Keyframe.ofFloat(0.3f, -shakeDegrees),
Keyframe.ofFloat(0.4f, shakeDegrees),
Keyframe.ofFloat(0.5f, -shakeDegrees),
Keyframe.ofFloat(0.6f, shakeDegrees),
Keyframe.ofFloat(0.7f, -shakeDegrees),
Keyframe.ofFloat(0.8f, shakeDegrees),
Keyframe.ofFloat(0.9f, -shakeDegrees),
Keyframe.ofFloat(1.0f, 0f)
);
ObjectAnimator objectAnimator = ObjectAnimator.ofPropertyValuesHolder(view, scaleXValuesHolder, scaleYValuesHolder, rotateValuesHolder);
objectAnimator.setDuration(duration);
if(isInfinite){
objectAnimator.setRepeatCount(Animation.INFINITE);
}
objectAnimator.start();
}