好用的漂浮、浮动动画

/**
 * 按钮浮动动画
 *
 * @param view
 */
@SuppressLint("WrongConstant")
private void initAnimation(View view) {
    List animators = new ArrayList<>();
    switch (view.getId()) {
        case R.id.iv_expo_comprofile:
            translationXAnim = ObjectAnimator.ofFloat(view, "translationX", -6.0f, 6.0f, -6.0f);
            translationYAnim = ObjectAnimator.ofFloat(view, "translationY", -3.0f, 3.0f, -3.0f);
            break;
        case R.id.iv_expo_prodispaly:
            translationXAnim = ObjectAnimator.ofFloat(view, "translationX", 6.0f, -6.0f, 6.0f);
            translationYAnim = ObjectAnimator.ofFloat(view, "translationY", -3.0f, 3.0f, -3.0f);
            break;
        case R.id.iv_expo_recreation:
            translationXAnim = ObjectAnimator.ofFloat(view, "translationX", -6.0f, 6.0f, -6.0f);
            translationYAnim = ObjectAnimator.ofFloat(view, "translationY", 3.0f, -3.0f, 3.0f);
            break;
        default:
            break;
    }
    translationXAnim.setDuration(2000);
    translationXAnim.setRepeatCount(ValueAnimator.INFINITE);
    translationXAnim.setRepeatMode(ValueAnimator.INFINITE);
    translationXAnim.start();
    animators.add(translationXAnim);
    translationYAnim.setDuration(1500);
    translationYAnim.setRepeatCount(ValueAnimator.INFINITE);
    translationYAnim.setRepeatMode(ValueAnimator.INFINITE);
    translationYAnim.start();
    animators.add(translationYAnim);

    AnimatorSet btnSexAnimatorSet = new AnimatorSet();
    btnSexAnimatorSet.playTogether(animators);
    btnSexAnimatorSet.setStartDelay(10000);
    btnSexAnimatorSet.start();
}

你可能感兴趣的:(Android杂谈,帮助)