【问题标题】:add view to vertical linearlayout inside horizontallscrollview within scrollview将视图添加到滚动视图内的水平滚动视图内的垂直线性布局
【发布时间】: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 线性布局,我只会得到一个视图,并且它下面有空闲空间。如果我这样评论 Horizo​​ntallScrollView:

<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) 和 Horizo​​ntalScrollView 组成的线性布局

标签: android scrollview android-linearlayout horizontalscrollview


【解决方案1】:

答案是在horizo​​ntalScrollview中将linearlayout的android:layout_width属性改为wrap_content

【讨论】:

  • 非常感谢。好技术点。现在我可以在 Horizo​​ntalscrollview 内进行垂直线性布局。
猜你喜欢
  • 2013-07-18
  • 1970-01-01
  • 1970-01-01
  • 2015-12-21
  • 2015-01-27
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2023-04-07
相关资源
最近更新 更多