Android,如何取消TextView上的闪烁动画?

时间:2014-05-27 12:39:48

标签: android

我试图在textview上启用和禁用闪烁动画。

开始闪烁工作正常,但停止闪烁就可以了:

anim.cancel();
anim.reset();

无法正常工作并抛出Null指针异常。 (但我不知道为什么,因为变量已初始化)。

我该如何解决?谢谢你的建议。

这是我的代码>

private Animation anim;


public void startBlinkText() {
        TextView myText = (TextView) findViewById(R.id.state);
        anim = new AlphaAnimation(0.0f, 1.0f);
        anim.setDuration(200); //You can manage the time of the blink with this parameter
        anim.setStartOffset(20);
        anim.setRepeatMode(Animation.REVERSE);
        anim.setRepeatCount(Animation.INFINITE);
        myText.startAnimation(anim);
    }

    public void stopBlinkText() {
        try {
            // TextView myText = (TextView) findViewById(R.id.state);
            anim.cancel();
            anim.reset();
            // myText.startAnimation(anim);
        } catch (Exception e) {
            Log.e(AppHelper.APP_LOG_NAMESPACE,
                    "stopBlinkText method cannot be processed", e);
            e.printStackTrace();
        }
    }

1 个答案:

答案 0 :(得分:0)

使用clearAnimation()停止动画。视图

上没有loadAnimation()clear()