重複の可能性:
Androidでボタンを動的に追加する方法は?
xml を使用せずに Android でボタンを作成する必要があります。次のコードを試しました。
Button b=new Button(this);
b.setWidth(50);
ただし、実行時には表示されません。
重複の可能性:
Androidでボタンを動的に追加する方法は?
xml を使用せずに Android でボタンを作成する必要があります。次のコードを試しました。
Button b=new Button(this);
b.setWidth(50);
ただし、実行時には表示されません。
Button myButton = new Button(this);
myButton.setText("Push Me");
myButton.height = 60;
myButton.width = 60;
LinearLayout ll = (LinearLayout)findViewById(R.id.buttonlayout);
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
ll.addView(myButton, lp);
ビューを画面に表示する前に、ビューをレイアウトに追加する必要があります。
Button b=new Button(this);
b.setWidth(50);
LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
layout.addView(b);