我有一个谷歌地图应用程序(使用谷歌地图:16)。 ProgressView 是自定义类布局,我用它来显示带有文本的 ProgressBar。问题是,当我转到 map fragment 时,如果 GPS 打开,它将尝试获取用户当前位置。在获取当前位置时,为了显示进度,我在 MapView 上方显示 ProgressView 和一些文本。工具栏中有一个后退按钮。每当我单击工具栏中的后退按钮时,有时 ProgressView 后面的谷歌地图部分会闪烁。这种情况只是偶尔发生。只有当我在 Samsung Galaxy S8 (API 26) 上运行我的应用程序时,它才会出现。
当我从布局中删除 ProgressView 时,不会出现闪烁,但需要显示进度 View 。下面是该 fragment 的布局:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="33.753746"
map:cameraTargetLng="-84.386330"
map:cameraZoom="14" />
<ProgressView
android:id="@+id/findProgressView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="gone" />
</FrameLayout>
预期结果是 Google map 不应随 ProgressView 一起闪烁。
最佳答案
也有类似的问题,MapView
在专门按下工具栏
的后退按钮时闪烁。
我确实尝试过测试 Andrey Smolyak的答案,它似乎确实有效。
尽管如此,我的 final方法是将 MapView
的 LayerType
更改为 XML 中的“硬件加速”。
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layerType="hardware"
android:layout_width="match_parent"
android:layout_height="match_parent" />
同样可以在 Java/Kotlin 代码中实现:
mapView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
关于android - 单击后退按钮时,Google map 在进度 View 后面闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55355267/