嗨,我正在尝试构建一个布局,其中每 2 秒会弹出一些形状。如果用户单击这些形状之一,它们必须消失。
这样做的正确方法是什么?我想了一个线程,但我错过了。这是我目前的代码(不工作):
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
l = new LinearLayout(this);
setContentView(l);
int counter = 1;
View v = new CustomDrawableView(this,20,50);
l.addView(v);
Thread t = new Thread() {
public void run() {
while (true) {
Log.i("THREAD","INSIDE");
View h = new CustomDrawableView(c,
(int)Math.round(Math.random()*100),
(int)Math.round(Math.random()*100));
SystemClock.sleep(2000);
l.addView(h);
}
}
};
t.start();
}