メソッド createButton を使用して、ランダムな位置に特定の数のボタンを Relativ Layout に追加したいと考えています。しかし、ボタンはすべて同時に表示されるのではなく、次々に表示されるはずであり、これを実現する方法がわかりません。
皆さんありがとう。
public void createButton(int amountOfButtons) {
Random r = new Random();
int i1 = r.nextInt(300);
int i2 = r.nextInt(300);
Button myButton = new Button(this);
myButton.setText("Push Me");
RelativeLayout ll = (RelativeLayout)findViewById(R.id.rela);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(50, 50);
lp.setMargins(i1,i2,0,0);
myButton.setLayoutParams(lp);
ll.addView(myButton);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (amountOfButtons > 1) {
createButton(amountOfButtons-1);
}
}