更新时间:2023-02-06 08:42:01
你可以使用 View.postDelayed(Runanble r,long delayMillis)
。例如:
public void onCreate() {
...
ImageView backgroundImageView = findViewById(R.id.background);
backgroundImageView.postDelayed(new Runnable() {
static int i = 0;
public void run() {
ImageView.this.setImageResource(
i++ % 2 == 0 ?
R.drawable.background_image1 :
R.drawable.background_image2);
ImageView.this.postDelayed(this, 1000);
}
}, 1000);
}