TableLayout relativeLayout = (TableLayout)findViewById(R.id.ll1);
TableRow row =new TableRow(this);
Button button ;
int counter = 0;
for(int i = 0;i<=13;i++){
counter++;
button = new Button(this);
button.setText(counter);
row.addView(button);
}
relativeLayout.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
relativeLayout.computeScroll();
XMLファイルレイアウトやボタン
<TableLayout android:id="@+id/ll1" android:shrinkColumns="true"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button1"
xmlns:android="http://schemas.android.com/apk/res/android"></TableLayout>
しかし、私は自分のアプリケーションを実行するたびに、それだけで一列に私のボタンを移動し、5つのボタンの後にすべてのボタンが画面から外に移動。私はいくつかのコードを置くようなコードをハードコードしたくないので、(counter%5 == 0)そしてこれを行うと、もっと多くの行を追加したいのです。
ボタンの幅が画面の幅と等しい場合は、幅を計算する他の方法はありませんか?それとも、または単に行の内容を折り返すテーブルレイアウトのプロパティのように他の方法ですか?
行が1つしかない場合は、LinearLayoutを使用してください。私はあなたがしたいことを実際に理解していないのですか?レイアウトにボタンを追加したときに何が起こるべきか、それらが画面上にどのように表示されるべきか - 1行、複数行??? – nenito