【发布时间】:2013-06-13 08:57:23
【问题描述】:
我想以编程方式将视图添加到 Scrollview 内的水平滚动视图内的垂直方向线性布局。我的布局的基本方案如下:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<HorizontalScrollView
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<LinearLayout
android:id="@+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</HorizontalScrollView>
</ScrollView>
现在,如果我以编程方式将 5 个视图添加到 list_view 线性布局,我只会得到一个视图,并且它下面有空闲空间。如果我这样评论 HorizontallScrollView:
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true"
android:fadingEdge="none">
<LinearLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- same header code -->
</LinearLaout>
<LinearLayout
android:id="@+id/list_view"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"/>
</ScrollView>
所有视图都显示正确,但它们不能水平滚动。请给我同样的想法如何解决这个问题。
【问题讨论】:
-
ScrollView 只允许一个孩子...您正在添加 2。该布局将不起作用
-
我认为滚动视图不允许多个孩子。请检查一次。
-
我同意@gunar 和@"Suresh Kumar Reddy Dangatla" 这种布局方案是错误的,但在我的滚动视图项目中,我有由 LinearLayout(@+id/header) 和 HorizontalScrollView 组成的线性布局
标签: android scrollview android-linearlayout horizontalscrollview