【问题标题】:Scroll view not wrapping around its content滚动视图不环绕其内容
【发布时间】:2012-07-17 09:07:32
【问题描述】:

我遇到了这样的问题:我在它下面有一个 MapView 和一个 ListView。地图大小是固定的。但我需要一起滚动我的视图。我以某种方式处理了非滚动地图和单项列表的问题,但出现了另一个问题 - 在 ScrollView 中,ListView 下方有很多可用空间,我无法摆脱它。我认为将列表设置为“wrap_content”会有所帮助,但事实并非如此。 该怎么办? 这是我的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <com.package.MyMapView
                     android:layout_width="match_parent"
                     android:layout_height="100dp"
                     android:clickable="true"
                     android:apiKey="key"
                     android:id="@+id/map"
                     android:layout_gravity="top"/>
        <ListView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/channelsList" >

        </ListView>

    </LinearLayout>

    </ScrollView>
</LinearLayout>

【问题讨论】:

    标签: android listview scrollview


    【解决方案1】:

    ListView 包裹在 ScrollView 中始终不是一个好主意,因为两者都是可滚动的视图。

    【讨论】:

    • 我知道。像这样的答案有很多问题,但我不问这是不是一个好主意,我只是有一个我必须实现的目标。目标是:我需要一个带有地图和列表的“页面”,它们应该可以一起滚动。
    • 所以如果你滚动地图,列表也会滚动?
    • 不。滚动视图中有两个视图。我需要滚动地图以查看它。但是当我向下滚动列表时,我需要地图在列表滚动时离开屏幕。
    • 然后尝试将 Map 添加为 ListView 的标题视图
    【解决方案2】:

    您可以尝试替换这些行吗:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    

    这些行:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >
    

    【讨论】:

    • fill_parent 已替换为 match_parent。意思相同,但应该使用后一个。
    【解决方案3】:

    不要在 ScrollView 中插入任何 ListView, 在任何情况下都不能满足您的要求。尝试将 MapView 作为标题添加到您的 ListView 以使其与您的列表一起滚动。

    要将 mapView 实现为标头,在您的 java 代码中,只需将 addHeaderView(&lt;your_map_view&gt;) 包含到您的 listView 组件中。这必须在调用setAdapter() 之前调用。

    【讨论】:

    • 我试过了,但我无法将地图添加为标题。现在我得到了工作地图和一个列表,他的问题是:在我的列表下面有很多空白空间。哪个(我想)不应该在那里
    猜你喜欢
    • 2017-10-05
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-16
    • 1970-01-01
    相关资源
    最近更新 更多