【发布时间】:2016-11-14 01:46:00
【问题描述】:
我想使用ValueAnimator 使TextView 的文本颜色在两种不同颜色之间闪烁两次,但我想在 XML 中创建动画。我找不到任何例子。任何帮助将不胜感激。
更新
下面的代码完美运行。颜色从黑色变为蓝色、蓝色变为黑色、黑色变为蓝色、蓝色变为黑色,每次反向重复之间的间隔为 500 毫秒。然而,我试图让这个从动画 xml 文件中工作。
ValueAnimator colorAnim = ObjectAnimator.OfInt(objectToFlash, "textColor", (int)fromColor, (int)toColor);
colorAnim.SetDuration(500);
colorAnim.SetEvaluator(new ArgbEvaluator());
colorAnim.RepeatCount = 3;
colorAnim.RepeatMode = ValueAnimatorRepeatMode.Reverse;
xml
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:propertyName="textColor"
android:duration="500"
android:valueFrom="@color/black"
android:valueTo="@color/ei_blue"
android:repeatCount="3"
android:repeatMode="reverse" />
代码
ValueAnimator anim = (ObjectAnimator)AnimatorInflater.LoadAnimator(Activity, Resource.Animator.blinking_text);
anim.SetTarget(objectToFlash);
使用 xml 会导致 TextView 的文本颜色在 500 毫秒内尽可能多地更改。
更新 我认为我需要的是在 xml 中模仿 OfInt 调用以编程方式执行的关键帧。现在正在尝试,但到目前为止没有运气。
【问题讨论】:
标签: android animation xamarin.android