我有一个从 View
扩展的自定义 View ,其中以不同角度绘制了大量文本,我希望特定字符串在第一次启动后将其 alpha 值降低到某个级别一次。任何建议或 fragment 将不胜感激:)
postInvalidateDelayed(...)
似乎不适用于此任务。
最佳答案
一种可能是在 FrameLayout
中创建两个相互重叠的 View 。一个 View 将包含所有静态字符串,另一个 View 将包含您想要设置动画的字符串。然后向动画 View 添加 alpha 动画将是一件简单的事情。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<package.MyNonAnimatedView
android:id="@+id/nonAnimatedView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<package.MyAnimatedView
android:id="@+id/animatedView"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
对于动画,您将附加到动画 View :
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator"
android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="100" />
在 Activity 的 onCreate(Bundle)
方法中,您可以调用 AnimationUtils.loadAnimation(Context, int)
从 xml 资源加载动画并将其附加到动画 View (前提是你给它一个 id)。
关于android - Canvas 上字符串的简单淡出动画,android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9339293/