Android 如何使用ListView使片段可滚动

Android 如何使用ListView使片段可滚动,android,listview,android-fragments,android-listview,Android,Listview,Android Fragments,Android Listview,我想要一个有2个ListView的片段。我不希望listView滚动,而是希望整个片段滚动。代码如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="matc

我想要一个有2个ListView的片段。我不希望listView滚动,而是希望整个片段滚动。代码如下:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff" >

    <TextView
        android:id="@+id/day"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:gravity="center_horizontal"
        android:paddingTop="15dp"
        android:text="Monday"
        android:textColor="#000"
        android:textSize="55sp" />

    <TextView
        android:id="@+id/date"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/day"
        android:gravity="center_horizontal"
        android:text="27 April, 2014"
        android:textColor="#000"
        android:textSize="45sp" />

    <ListView
        android:id="@+id/home_list_time"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/date"
        android:layout_margin="10dp"
        android:background="@color/list_home_time_bg"
        android:divider="@android:color/white"
        android:dividerHeight="20.0sp" />

    <ListView
        android:id="@+id/home_list_stime"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/home_list_time"
        android:layout_margin="10dp"
        android:background="@color/list_home_stime_bg"
        android:divider="@android:color/white"
        android:dividerHeight="20.0sp" />

    </RelativeLayout>


当我运行此代码时,第二个listView会有自己的滚动条,有没有办法停止此操作并使整个片段滚动?

要停止listView滚动,请使用-

listView.setScrollContainer(false);
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <!-- everything you already have -->
</ScrollView>
要滚动片段,请将其放在ScrollView中-

listView.setScrollContainer(false);
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <!-- everything you already have -->
</ScrollView>

更多信息-。

我认为这是个坏主意,但您是否尝试过将RelativeLayout包装在滚动视图中?我想你会看到一些奇怪的滚动行为和/或ListView的高度可能不是你所期望的。这是因为当测量未填充的listview时,scrollview有点咄咄逼人。出于某种原因,现在listview只显示第一个元素,我们需要滚动查看其余元素,而整个片段活动并没有占据移动屏幕的高度。你的答案应该有用,但我不知道怎么了。。。如果我们将listView设置为false,为什么它仍在滚动?