I am trying to add delay while adding view to mainview but views spear simultaneously. Please help.
final Handler handler = new Handler();
LinearLayout ll = (LinearLayout)findViewById(R.id.ll);
final HorizontalScrollView hsv = new HorizontalScrollView(TestViewActivity.this);
final LinearLayout lhsv = new LinearLayout(TestViewActivity.this);
final Animation a1 = new AlphaAnimation(0.00f, 1.00f);
a1.setDuration(350);
a1.setFillAfter(true);
for(int k =0; k < 5; k++){
new Handler().postDelayed(new Runnable() {
public void run() {
//write your code here...
TextView tv = new TextView(TestViewActivity.this);
tv.setText("Text");
tv.setTextSize(42);
tv.setPadding(10, 0, 10, 0);
tv.setVisibility(View.INVISIBLE);
tv.clearAnimation();
tv.startAnimation(a1);
lhsv.addView(tv, temp);
temp++;
}
}, 2000);
}
hsv.addView(lhsv);
ll.addView(hsv);
temp is static int.
according to your code, result may be adding all views simultaneously after 2second, right?
the delay time must be changed by int k like below.
and I recommend to don’t make handler which is not necessary. just post runnables to one handler.