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