在滚动时滚动查看滚动视图内的Recyclerview显示黑色闪烁背景

时间:2017-12-05 05:57:36

标签: android google-maps android-recyclerview scrollview

我在recyclerview行中使用了地图视图。 我附上了截图。 滚动地图显示黑色闪烁背景。

check my screenshot

适配器代码:

 <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="150dp">

            <com.google.android.gms.maps.MapView
                android:id="@+id/checkInMapView"
                android:layout_width="0dp"
                android:layout_height="150dp"
                android:layout_weight="1"
                android:enabled="true"
                android:visibility="gone"
                map:cameraZoom="15"
                map:liteMode="true"
                map:mapType="normal" />

         <!--   I have also tried adding transparent view as below but still no solution.

        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/transparent"/>-->

        </LinearLayout>
  

我引用此链接:Link   但是在这个演示中他们在我的代码中使用了数组适配器,我们使用了recyclelerview适配器。

xml代码:

 onBindCheckInViewHolder(...){
 holder.mapView.onCreate(null);
            holder.mapView.getMapAsync(googleMap -> {
                MapsInitializer.initialize(context);
                gMap = googleMap;
                googleMap.getUiSettings().setMapToolbarEnabled(false);
                moveMap(gMap, singleCheckIn.getLatitude(), singleCheckIn.getLongitude());
            });
      }
  

我没有执行任何放大,缩小或拖动。   提前谢谢。

Google Issue Track

  

更新

以前我在viewHolder中初始化map而不是上面提到的场景。

{{1}}

4 个答案:

答案 0 :(得分:3)

在AndroidManifest.xml中写下这一行:

android:hardwareAccelerated="true"
 <application
        android:name="com.xyz"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
</application>

有效。

答案 1 :(得分:2)

所以我稍微挖了一下,这里有一些建议让性能好一些,但它并不完美,但速度要快得多。

地图类型

这基本上决定了地图的外观(普通/混合......等),在这些情况下你需要将地图类型设置为GoogleMap.MAP_TYPE_NONE

  • XML您定义视图的位置,因此这是默认类型
  • 覆盖适配器中的onViewRecycled,如果holder GoogleMap将其类型设置为无

在调用GoogleMap.MAP_TYPE_NORMAL时,只需将您的类型设置回onBindViewHolder或您想要的任何类型。

预初始化

MapsInitializer.initialize(context)回拨中致电onMapReady

<强>初始化

GoogleMap.onCreate()致电GoogleMap.getMapAsync()onCreateViewHolder,也许在您的ViewHolder构造函数中。

RecyclerView预取

您还可以使用LinearLayoutManager的简洁新功能,您可以拨打LinearLayoutManager.setInitialPrefetchItemCount,开始准备关闭屏幕项目。

并非这会导致其他性能问题,请进行调整直至获得良好的平衡。

优化布局

  • 尝试将RecyclerView平放的布局设为 可能,不要嵌套过多的布局
  • 确保为setHasFixedSize(true)
  • 设置RecyclerView
  • 请务必避免使用权重或RelativeLayout作为RecyclerView或您子项列表项的父项。

答案 2 :(得分:1)

<application
    android:name="com.yourpackagename"
    android:allowBackup="true"
    android:hardwareAccelerated="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

只需在项目清单文件中将hardwareAccelerated添加为True

答案 3 :(得分:0)

MapView是一个相当沉重的视图,当你试图在屏幕上获得一堆它们时,app会在滚动时变得迟钝。您可以将纬度和经度等数据作为字符串传递,其中一些静态变量取自下面提到的链接。你可以从Facebook API获得坐标。 这是api链接https://developers.google.com/maps/documentation/staticmaps/

 String getMapURL = "http://maps.googleapis.com/maps/api/staticmap?zoom=
                    18&size=560x240&markers=size:mid|color:red|"  
                    + JOLocation.getString("latitude") + "," + JOLocation.getString("longitude")
                    + "&sensor=false";

当您在浏览器中使用时,上面构造的URL会返回.PNG文件。 此链接中讨论了类似类型的问题MapView in Listview。希望它有所帮助

相关问题