我可以实现淡出效果,但无法实现缩小效果。我希望它看起来像是远远地消失在远方。
我想要一个类似于www.screamintothevoid.com网站使用的动画效果。
那应该可以按照您的要求工作。
/res/anim 中的 animation.xml
<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);
要缩小视图,请更改其比例值,例如:
TextView textToShrink = (TextView) findViewById(R.id.text_to_shrink);
textToShrink.animate().scaleX(0.3f).scaleY(0.3f).setDuration(600).start();
使用androidx库的帮助类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());