android 动画

组合动画:位移和缩放

public void animateImageToBig(ImageView imageView) {
        // 放大 ImageView
        if (imageView.getScaleX() <= 1.0f) {
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 1.0f, 1.55f);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 1.0f, 1.55f);
            ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", 0f, UiUtil.dp2px(-5));
            AnimatorSet set = new AnimatorSet();
            set.playTogether(scaleX, scaleY,translationY);
            set.start();
        }
    }

    public void animateImageToSmall(ImageView imageView) {
        // 还原 ImageView
        if (imageView.getScaleX() > 1.0f) {
            ObjectAnimator scaleX = ObjectAnimator.ofFloat(imageView, View.SCALE_X, 1.55f, 1.0f);
            ObjectAnimator scaleY = ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 1.55f, 1.0f);
            ObjectAnimator translationY = ObjectAnimator.ofFloat(imageView, "translationY", 0f, 0f);
            AnimatorSet set = new AnimatorSet();
            set.playTogether(scaleX, scaleY,translationY);
            set.start();
        }
    }

动画:平移

TranslateAnimation translateAnimation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                    0,Animation.RELATIVE_TO_SELF,UiUtil.dp2px(-5));
// 位移之后保持
translateAnimation.setFillAfter(true);
imageView.startAnimation(translateAnimation);

你可能感兴趣的:(动画,android)