我正在尝试在每个之间添加1秒ImageView
的4 X delay
,
我的代码是:
final LinearLayout ll = (LinearLayout) findViewById(R.id.container);
for (int j=0;j<4;j++){
final ImageView newIMG = new ImageView(this);
newIMG.setLayoutParams(
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT,
1.0f));
newIMG.setImageResource(R.drawable.new_image);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
ll.addView(newIMG);
}
}, 1000);
}
但是我得到的是-它等待一秒钟,然后立即
display
所有ImageViews
...(我希望他们一个接一个地展示)
最佳答案
尝试:
final LinearLayout ll = (LinearLayout) findViewById(R.id.container);
for (int j=0;j<4;j++){
final ImageView newIMG = new ImageView(this);
newIMG.setLayoutParams(
new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.MATCH_PARENT,
1.0f));
newIMG.setImageResource(R.drawable.new_image);
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
ll.addView(newIMG);
}
}, j*1000 + 1000);
}