-1

私は作成していますTableLayout

のxmlコードTableLayout:

<TableLayout
        android:id="@+id/productList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
</TableLayout>

n行を動的に追加したいのですが、この画像のように各行に2 列だけが必要です

動的に2列のTableView

レイアウトファイルで使用android:strechColumnsしましたが、成功しません。

この問題を動的に解決するにはどうすればよいですか?

助けてください...

前もって感謝します。

4

2 に答える 2

1
 <TableLayout 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="3"
    android:id="@+id/tableLayout"
     >

    <TableRow>
        <LinearLayout 
            android:layout_height="wrap_content"
            android:layout_width="0dp"
            android:weightSum="3">

            <View android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="1"
            </View>
            <View android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="1"
            </View>
            <View android:layout_width="0dp" 
                android:layout_height="wrap_content" 
                android:layout_weight="1"
            </View>
        </LinearLayout>
     </TableLayout>

 TableLayout tl=(TableLayout)findViewById(R.id.tableLayout);    
 TableRow tr1 = new TableRow(this);
 tr1.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
 t1.addView(tr1);
 LinearLayout ll = new LinearLayout(this);
 ll.setOrientation(LinearLayout.HORIZONTAL);
//LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width, height, weight);
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0dp,LayoutParams.WRAP_CONTENT, 3);
  tr1.addView(ll, params);
  View v1= new View(this);
  View v2= new View(this);
  View v3= new View(this);
  ll.addView(v1, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1));
  ll.addView(v2, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1));
  ll.addView(v3, new LayoutParams(0dp, LayoutParams.WRAP_CONTENT,1));
于 2013-10-04T06:14:57.183 に答える