相关疑难解决方法(0)

使用ValueAnimator使TextView闪烁不同的颜色

我想使用a ValueAnimator来使TextView两种不同颜色之间的文本颜色闪烁两次,但我想用XML创建动画.我找不到任何例子.任何帮助将不胜感激.

更新

下面的代码非常完美.颜色从黑色变为蓝色,蓝色变为黑色,黑色变为蓝色,蓝色变为黑色,每次反向重复之间的颜色变为500ms.然而,我试图从animator 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;
Run Code Online (Sandbox Code Playgroud)

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" /> 
Run Code Online (Sandbox Code Playgroud)

ValueAnimator anim = (ObjectAnimator)AnimatorInflater.LoadAnimator(Activity, Resource.Animator.blinking_text);
anim.SetTarget(objectToFlash);
Run Code Online (Sandbox Code Playgroud)

使用xml会导致TextView文本颜色的颜色在500毫秒内变化多少次.

更新 我认为我需要的是在xml中模仿OfInt调用正在以编程方式执行的操作的关键帧.现在尝试这个,但到目前为止没有运气.

animation android xamarin.android

22
推荐指数
1
解决办法
3万
查看次数

文字颜色动画

有没有办法动画文本颜色变化(从任何颜色变为白色)?

我想出的唯一变体是将两个文本视图(具有相同的文本)放在一个地方,然后淡化顶部的一个,因此底部的一个(具有白色)将变得可见.

PS我废弃了2个TextViews的变体,因为它看起来很奇怪(边缘不平滑,因为我在屏幕上有很多这样的元素,它真的落后于滚动).我做了什么,是一个疯狂的黑客,使用Thread和setTextColor(也强制重绘textview)来动画.

由于我只需要2种颜色变化(从红色到白色,从绿色到白色),我硬编码了它们之间的值和所有过渡颜色.所以这是它的样子:

public class BlinkingTextView extends TextView {
public BlinkingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public void animateBlink(final boolean red) {
    if (animator != null) {
        animator.drop();
    }
    animator = new Animator(this, red);
    animator.start();
}

public void clearBlinkAnimation() {
    if (animator != null) {
        animator.drop();
    }
}

private Animator animator;

private final static class Animator extends Thread {
    public Animator(final TextView textView, final boolean red) {
        this.textView = textView;
        if (red) {
            SET_TO_USE = RED;
        } …
Run Code Online (Sandbox Code Playgroud)

android

13
推荐指数
3
解决办法
2万
查看次数

标签 统计

android ×2

animation ×1

xamarin.android ×1