我有一个名为
的xml文件rowitem.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
}
我试图通过充气器获得它,但它不起作用
答案 0 :(得分: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);
}