Android 无法以编程方式添加视图
我有后续问题。我有一个滚动视图,如:Android 无法以编程方式添加视图,android,android-layout,view,Android,Android Layout,View,我有后续问题。我有一个滚动视图,如: <ScrollView android:layout_width="wrap_content" android:layout_height="wrap_content" > <LinearLayout android:id="@+id/linearInsideScroll" android:layout_width="match_parent" android:la
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="@+id/linearInsideScroll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
android:id="@+id/row1"
android:layout_width="fill_parent"
layout="@layout/catalog_row" />
<include layout="@layout/horizontal_row" />
<include
android:id="@+id/row2"
android:layout_width="fill_parent"
layout="@layout/catalog_row" />
<include layout="@layout/horizontal_row" />
....
但奇怪的事情发生了。只有第一行视图添加到布局中,而不是水平行。
出什么事了?我不明白这里有一件事,你为什么要再次添加这个
layout horizontal\u row
?此布局已在主布局中添加了
。因为当事件发生时,添加新的第一行视图(在xml中声明的水平行下),然后在第一行下添加另一个水平行。滚动视图就像:“目录行”-“水平行”-“目录行”-“水平行”-“目录行”-“目录行”-“水平行”-“目录行”-“水平行”-…好的。然后逐个展开布局并添加到滚动视图中。并从主布局中删除静态。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="20dip" >
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0"
android:background="#FFFFFF" />
</RelativeLayout>
LinearLayout linearLayout = (LinearLayout) view
.findViewById(R.id.linearInsideScroll);
View firstRow = inflater.inflate(R.layout.catalog_row, null, false);
...
linearLayout.addView(firstRow);
linearLayout.addView(inflater.inflate(R.layout.horizontal_row,
null, false));