RecyclerView下的交互式MapView

时间:2019-07-01 10:07:24

标签: android android-recyclerview android-mapview android-maps-v2

假设我有这样的布局:

<androidx.core.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

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

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

        <com.google.android.gms.maps.MapView
            android:id="@+id/mapView"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:uiMapToolbar="false"
            />
    </LinearLayout>

</androidx.core.widget.NestedScrollView>

这符合我的需求,即

  • 在列表下显示地图,以使地图显示在列表的最后一项下
  • 让地图从用户那里接收触摸输入,以便可以平移,缩放等(没有精简模式)

Example

我发现有两个问题:

  • 没有回收,这意味着呈现列表所需的内存将随着列表中项目的数量而增加。我预计清单上不会有200多个相对简单的商品,经过分析后,我可能会说这不是一个大问题,但我当然希望继续回收。
  • 列表必须具有可扩展的项目,这意味着用户可以单击某些项目,然后回收者将从列表中添加/删除项目。如果展开的组中有很多项目,则测量会花费大量时间,从而在展开的动画中产生明显的颠簸,这是不可接受的。

我也尝试过将地图作为适配器的一项,但是在滚动列表时会引入很多麻烦,而且很尴尬,因为您需要将转发生命周期与地图的回收期适配器中的项的“生命周期”协调起来

那么您如何在列表下显示地图而又不会丢失回收或平滑滚动?

0 个答案:

没有答案