代码之家  ›  专栏  ›  技术社区  ›  Victor

ListView和ScrollView未正确显示[重复]

  •  -2
  • Victor  · 技术社区  · 12 年前

    我有两个按钮(工作正常)和一个 滚动视图包装的列表视图 .

    问题是列表被显示了,但我只能看到一个元素,我可以滚动,但屏幕的其余部分被浪费了,我希望列表视图能显示得尽可能大。

    这是我的布局XML:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Enviar" >
    
    <LinearLayout
        android:id="@+id/layhoriz"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
    
        <Button
            android:id="@+id/b_arriba"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Arriba" />
    
        <Button
            android:id="@+id/b_salir_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Salir" />
    </LinearLayout>
    
    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <ListView
            android:id="@+id/ListView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
        </ListView>
    </ScrollView>
    

    6 回复  |  直到 12 年前
        1
  •  1
  •   Damzeloca    12 年前

    尝试使用不带滚动视图的ListView元素,当元素数量超过屏幕上显示的元素时,滚动会在ListView上工作。

        3
  •  1
  •   Manmohan Soni    12 年前

    不需要在列表视图上使用滚动视图

        4
  •  0
  •   Community Mohan Dere    9 年前

    将任何可垂直滚动的视图组放在另一个垂直滚动视图组/容器中并不是最佳做法。

    看一看 here.

    如果你无论如何都想实现它,请查看 same post .

        5
  •  0
  •   s.d    12 年前

    您没有将自动展开视图(如 ListView )在 ScrollView .

    卷轴视图 设置为展开其内容并提供滚动,它没有自己设置的高度/宽度。因此,它的儿童观点不应该试图 match_parent .

    标记 列表视图 以具有固定的高度。

    我建议观看 this google presentation 关于 列表视图 s

        6
  •  0
  •   Jave    12 年前

    ListView 将自动滚动其内容,因此无需使用 ScrollView .