Android 同时缩小和淡出一个View的动画

Android animation to shrink and fade out a View at the same time

我可以淡出。但不是收缩。我希望它看起来像是要进入很远很远的地方。

我想要一个类似于 www.screamintothevoid.com

中使用的动画

要缩小视图,请更改其比例值,例如:

TextView textToShrink = (TextView) findViewById(R.id.text_to_shrink);
textToShrink.animate().scaleX(0.3f).scaleY(0.3f).setDuration(600).start();

这应该会如您所愿。

animation.xml 在 /res/anim

 <set xmlns:android="http://schemas.android.com/apk/res/android">
        <scale xmlns:android="http://schemas.android.com/apk/res/android"
            android:fromXScale="1"
            android:toXScale="0"
            android:fromYScale="1"
            android:toYScale="0"
            android:duration="5000"
            android:pivotX="50%"
            android:pivotY="50%" >
        </scale>

        <alpha
            android:fromAlpha="1"
            android:toAlpha="0"
            android:duration="5000" >
        </alpha>
    </set>

调用此动画:

TextView textView = (TextView) findViewById(R.id.text_view);
Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animation);
textView.startAnimation(animation);

您可以使用 androidx 库助手 class ViewCompat

在一行中淡出和缩小视图
import androidx.core.view.ViewCompat;
import android.view.animation.AccelerateInterpolator;

ViewCompat.animate(myView).alpha(0f).scaleX(0.5f).scaleY(0.5f).setDuration(600).setInterpolator(new AccelerateInterpolator());