gpt4 book ai didi

java - Android 弹出倒计时

转载 作者:行者123 更新时间:2023-12-02 00:10:26 24 4
gpt4 key购买 nike

我试图让一个圆圈在 3 秒后弹出,并在 3 秒内循环消失。这个程序在 3 秒后弹出圆圈,但我对 3 秒的持续时间有疑问。

如果有人能为我提供解决方案,那就太好了

public class TestView extends View{

private boolean isPop;

public TestView(Context context) {
super(context);

isPop=false;
// TODO Auto-generated constructor stub
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.RED);

Paint circle = new Paint();
circle.setColor(Color.BLUE);
if (isPop){
canvas.drawCircle(100, 100, 40, circle);
}
invalidate();

CountDownTimer count = new CountDownTimer(3000, 1000) {

public void onTick(long millisUntilFinished) {
}

public void onFinish() {

CountDownTimer count = new CountDownTimer(3000, 1000) {

public void onTick(long millisUntilFinished) {
isPop=true;

}

public void onFinish() {

isPop=false;

}

}.start();
}

}.start();

最佳答案

考虑使用每个 View 附带的处理程序:

class TestView extends View { 
private Paint circle = new Paint();
private boolean isPop = false;
private Runnable everyThreeSeconds = new Runnable() {
public void run() {
// Do something spiffy like...
isPop = !isPop;
invalidate();

// Don't forget to call you next three second interval!
postDelayed(everyThreeSeconds, 3000);
}
};

public TestView(Context context) {
this(context, null);
}

public TestView(Context context, AttributeSet attrs) {
super(context, attrs);
circle.setColor(Color.BLUE);
post(everyThreeSeconds);
}

@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.RED);

if (isPop){
canvas.drawCircle(100, 100, 40, circle);
}
}
}

关于java - Android 弹出倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12922306/

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