0

我有一个名为

行项目.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
            android:id="@+id/item"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

        <TextView android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <ImageButton android:id="@+id/pic"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@null" />

</LinearLayout>

我希望将此布局添加到 TableLayout 中的每个列项

for (int raw = 0; raw < 5; raw++) {
    TableRow tableRow = new TableRow(this);
    tableRow.setOrientation(TableRow.HORIZONTAL);

    // here I want to add the same rowitem.xml about four times in the same row

}

我试图用充气机得到它,但它不起作用

4

1 回答 1

2

尝试这个..

LayoutInflater vi= (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

TableRow tableRow = new TableRow(this);
tableRow.setOrientation(TableRow.HORIZONTAL);


for (int raw = 0; raw < 5; raw++)
{
  View v = vi.inflate(R.layout.rowItem, null);
  // here I want to add the same rowitem.xml about four times in the same row
  tableRow .addView(v);

}
于 2013-06-22T10:49:26.860 回答