Uiをプログラムで実行したいのですが、シンプルなボタンを使用していますが、画面の全幅を占めています。ボタンの幅をどのようにサイズ変更すればよいですか。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_main);
TextView label = new TextView(this);
label.setText("Hello");
label.setTextSize(20);
Button but = new Button(this);
but.setText("Click Me");
but.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
System.out.println("Button Clicked");
Intent myIntent = new Intent(v.getContext(), SecondActivity.class);
startActivityForResult(myIntent, 0);
}
});
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.addView(label);
ll.addView(but);
setContentView(ll);
}
このボタンを追加する必要がある別のレイアウトはありますか?プログラムによるレイアウトの理解を深めることに関するチュートリアルは役に立ちます。
よろしく Rakesh Shankar.P