【发布时间】:2011-07-20 11:09:54
【问题描述】:
我想在LinearLayout 中添加多个视图。这是我用于向LinearLayout 添加多个视图的代码。
Java 代码:
LinearLayout seriesMainListItemView = (LinearLayout) findViewById(R.id.SeriesMainListItemView);
LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for (int i=0; i<scheduleArr.length; i++) {
View inflatedView = mInflater.inflate(R.layout.scheduleitem, null);
TextView inflatertext1 = (TextView) inflatedView.findViewById(R.id.text1);
TextView inflatertext2 = (TextView) inflatedView.findViewById(R.id.text2);
inflatertext1.setText(scheduleArr[i][0]);
inflatertext2.setText(scheduleArr[i][1]);
Log.i("data",i + " " + scheduleArr[i][0] + "/" + scheduleArr[i][1]);
seriesMainListItemView.addView(inflatedView);
}
这是我要多次添加的 View xml。
这是我要添加的 LinearLayout。
<TableLayout
android:layout_gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="1dip"
android:paddingRight="1dip" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imgSeriesMainScheduleImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/scheduleheader"/>
<LinearLayout
android:id="@+id/SeriesMainListItemView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</TableRow>
..............
</TableLayout>
但只有单个视图添加到 LinearLayout 中,虽然数组的长度是 3。我的代码有什么问题?
【问题讨论】:
-
你设置了LinearLayout的方向了吗?
标签: android view android-linearlayout