Android:ListView无法在ScrollView中获得完整的layout_height

时间:2014-07-05 13:06:25

标签: android listview scrollbar scrollview fill-parent


我有两个问题:

  - 如何获得ListView的动态高度(fill_parent,match_parent)?如果我写" layout_height:fill_parent"它没有真正起作用

  - 如何在没有ScrollView的情况下获得解决方案,仅使用ListView? (没有ScrollView,我的滚动条离正确的站点太远了。)

Greets Robin

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#e7e7e7">

<TextView
    android:id="@+id/date_header"
    android:layout_width="wrap_content"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:background="#bfbfbf"
    android:gravity="center"
    android:text="05.07.2014"
    android:textAppearance="?android:attr/textAppearanceSmall" />

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/date_header"
    android:layout_centerHorizontal="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/listView1"
            android:layout_width="match_parent"
            android:layout_height="431dp"
            android:divider="@android:color/transparent"
            android:dividerHeight="15dp"
            android:paddingBottom="20dp"
            android:paddingLeft="15dp"
            android:paddingRight="15dp"
            android:paddingTop="20dp"
            android:scrollbars="none" >

        </ListView>

    </LinearLayout>
</ScrollView>

1 个答案:

答案 0 :(得分:0)

我认为不需要ScrollView

在设计时可能会收到警告:

  

垂直滚动的ScrollView不应包含其他内容   垂直滚动小部件(ListView)

您也可以使用它来实现您的设计:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#e7e7e7" >

    <TextView
        android:id="@+id/date_header"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="#bfbfbf"
        android:gravity="center"
        android:text="05.07.2014"
        android:textAppearance="?android:attr/textAppearanceSmall" />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/date_header"
        android:layout_marginTop="10dp"
        android:divider="@android:color/transparent"
        android:dividerHeight="15dp"
        android:scrollbars="none" >
    </ListView>

</RelativeLayout>