尝试使用倒数计时器
new CountDownTimer(300000, 1000) {
boolean visible = true;
public void onTick(long millisUntilFinished) {
ImageView v=(ImageView)findViewbyID(R.id.mypic);
if(visible)
v.setVisibility(View.INVISIBLE);
else
v.setVisibility(View.VISIBLE);
visible = !visible;
}
public void onFinish() {
}
}.start();
或者你甚至可以使用处理程序
Handler handler=new Handler()
{
boolean visible = true;
@Override
public void handleMessage(Message msg)
{
ImageView v=(ImageView)findViewbyID(R.id.mypic);
if(visible)
v.setVisibility(View.INVISIBLE);
else
v.setVisibility(View.VISIBLE);
visible = !visible;
handler.sendEmptyMessageDelayed(0, 1000);
}
};
handler.sendEmptyMessage(0);