如何创建颜色变化动画? (Android) [英] How to create color changing animation? (Android)
问题描述
我有一个 TextView
和一些文本。我需要创建一个动画持续时间为30秒,它会慢慢地将文本的颜色从绿色变为红色。任何想法?
I have a TextView
and some text in it. I need to create an animation with 30 seconds duration, and it will slowly change the color of text from green to red. Any ideas?
推荐答案
1)30s是一个真的,很长的时间,几乎没有任何用户会等待看到结束。
1) 30s is a really, really long time, hardly any users would wait to see the end of it.
2)请参阅使用ObjectAnimator 进行动画。像 ObjectAnimator.ofInt(textView,textColor,Color.GREEN,Color.RED)
应该做你想要的。然而,请注意,转换将是线性的,并且将经历很多中间颜色。直到它命中#FF0000
。你当然可以指定中间的点,但一般线性的颜色转换(在RGB)是不漂亮。
2) See Animating with ObjectAnimator. Something like ObjectAnimator.ofInt(textView, "textColor", Color.GREEN, Color.RED)
should do what you want. Note, however, that the transition will be linear and will go through a lot of intermediary colors. until it hits #FF0000
. You can of course specify the points in the middle but in general linear color transitions (in RGB) are not pretty.
这篇关于如何创建颜色变化动画? (Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!