ImageView可在android中缩小和缩放图像动画

ImageView可在android中缩小和缩放图像动画,android,android-animation,splash-screen,Android,Android Animation,Splash Screen,我希望图像缩小和缩放为Twitter闪屏动画,但我无法首先缩小图像和缩放。这是我的密码 imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { imageView.animate() .setStartDelay(500)

我希望图像缩小和缩放为Twitter闪屏动画,但我无法首先缩小图像和缩放。这是我的密码

imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            imageView.animate()
                    .setStartDelay(500)
                    .setDuration(1000)
                    .scaleX(20)
                    .scaleY(20)
                    .alpha(0);
        }
    });

你没有提到变量中的比例

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
    <scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5" >
    </scale>
 </set>

您没有提到变量的比例

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" >
    <scale
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="1.0"
    android:fromYScale="1.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="0.5"
    android:toYScale="0.5" >
    </scale>
 </set>

使用
ObjectAnimator
几乎可以制作任何动画,而且非常流畅

下面是一个示例代码。在这种情况下,图像将从1x放大到2x,您可以根据需要调整值。现在,如果要缩小,请将2x更改为0.5x,这将使图像缩小到原始图像的50%

    ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(imageView, "scaleX", 1.0f, 2.0f);
    scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleXAnimation.setDuration(1500);
    ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(imageView, "scaleY", 1.0f, 2.0f);
    scaleYAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleYAnimation.setDuration(1500);
    ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(imageView, "alpha", 1.0F, 0F);
    alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    alphaAnimation.setDuration(1500);


    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(scaleXAnimation).with(scaleYAnimation).with(alphaAnimation);
    animatorSet.setStartDelay(500);
    animatorSet.start();

您几乎可以使用
ObjectAnimator
制作任何动画,而且非常流畅

下面是一个示例代码。在这种情况下,图像将从1x放大到2x,您可以根据需要调整值。现在,如果要缩小,请将2x更改为0.5x,这将使图像缩小到原始图像的50%

    ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(imageView, "scaleX", 1.0f, 2.0f);
    scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleXAnimation.setDuration(1500);
    ObjectAnimator scaleYAnimation = ObjectAnimator.ofFloat(imageView, "scaleY", 1.0f, 2.0f);
    scaleYAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleYAnimation.setDuration(1500);
    ObjectAnimator alphaAnimation = ObjectAnimator.ofFloat(imageView, "alpha", 1.0F, 0F);
    alphaAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    alphaAnimation.setDuration(1500);


    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.play(scaleXAnimation).with(scaleYAnimation).with(alphaAnimation);
    animatorSet.setStartDelay(500);
    animatorSet.start();