Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android,如何取消TextView上的闪烁动画?_Android - Fatal编程技术网

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

Android,如何取消TextView上的闪烁动画?,android,Android,我正在尝试启用和禁用textview上的闪烁动画 开始闪烁工作正常,但停止闪烁不适用于: anim.cancel(); anim.reset(); 不工作并引发空指针异常。(但我不知道为什么,因为变量已初始化) 我怎样才能解决这个问题?谢谢你的建议 这是我的代码> private Animation anim; public void startBlinkText() { TextView myText = (TextView) findViewById(R.id.stat

我正在尝试启用和禁用textview上的闪烁动画

开始闪烁工作正常,但停止闪烁不适用于:

anim.cancel();
anim.reset();
不工作并引发空指针异常。(但我不知道为什么,因为变量已初始化)

我怎样才能解决这个问题?谢谢你的建议

这是我的代码>

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();
        }
    }

使用
clearAnimation()
停止动画。视图中没有
loadAnimation()
clear()

尝试使用
textView.clearAnimation()…这是我的真实代码,你需要整个活动吗?什么时候调用了
startLinkText()
stopBlinkText()
?这里回答了你的问题:对不起,伙计们。我发现了问题所在。clearAnimation方法是在textview的新初始化之后调用的。如果我删除了新的init,问题就解决了。