gpt4 book ai didi

android - 如何让 Android 中的 Button 闪烁?

转载 作者:行者123 更新时间:2023-11-29 15:01:43 28 4
gpt4 key购买 nike

如果用户(在我的问答游戏中)选择了错误答案,则正确答案的按钮应呈绿色闪烁。到目前为止,我是这样做的:

    if(answerTrue)
for (int i = 0; i < 2000; i = i + 250) {
handler.postDelayed(rbl_blinkNormal, i);
i = i + 250;
handler.postDelayed(rbl_blinkGreen, i);
}

还有可运行的:绿色:

 rbl_blinkGreen= new Runnable() {
@Override
public void run() {
btn_richtig.setBackgroundResource(R.drawable.color_green_btn);
}

};

正常:

 rbl_blinkNormal= new Runnable() {
@Override
public void run() {
btn_richtig.setBackgroundResource(R.drawable.color_black_btn);
}

};

它工作正常但像这样我每 250 毫秒调用一次 postDelayed()。这会影响我的应用程序性能吗?有没有更好的方法来做到这一点?

最佳答案

一旦您将按钮的颜色设置为绿色,您就可以为按钮设置动画。我的意思是,

if(answerTrue){

// Set the color of the button to GREEN once.

// Next, animate its visibility with the set color - which is GREEN as follows:

Animation anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(50); //You can manage the blinking time with this parameter
anim.setStartOffset(20);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(Animation.INFINITE);
button.startAnimation(anim);
}

同样,您可以为另一个按钮设置动画并在需要时停止动画。

来源: Blinking Text in android view

关于android - 如何让 Android 中的 Button 闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43705249/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com