-1


我有两个问题:

- 如何为我的 ListView 获取动态高度(fill_parent,match_parent)?如果我写“layout_height:fill_parent”,它就不能正常工作

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

问候罗宾

<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>

4

1 回答 1

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>
于 2014-07-05T13:22:13.653 回答