从另一个Fragment弹出后,Google的SupportMapFragment MapView的性能降低

时间:2019-04-10 13:54:35

标签: android performance kotlin google-maps-android-api-2 android-architecture-navigation

SupportMapFragment滞后,并且从堆栈返回后,它们的整体性能都不好。

该问题很奇怪,因为我将导航图用于导航目的,并且该问题并不总是存在。这是两种不同的情况:

MapFragment-> AnotherFragment(通过ActionBar菜单项)-> Mapfragment

override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        onNavDestinationSelected(item!!, navController)
        return super.onOptionsItemSelected(item)
    }

在这种情况下,在AnotherFragment中按下向后按钮后,MapFragment滞后了

MapFragment-> AnotherFragment(通过默认按钮)-> Mapfragment

navController.navigate(R.id.action_mapFragment_to_anotherFragment)

在这种情况下,MapFragment正常运行。

我尝试在navController.navigate(R.id.action_mapFragment_to_anotherFragment)中使用onOptionsItemSelected(item: MenuItem?),但最终得到了相同的结果。

我也知道this这个问题,但同样的问题,但是在完全不同的情况下,答案也没有帮助。

1 个答案:

答案 0 :(得分:0)

因此问题不在于Mapfragment或Google的SupportMapFragment,而在于某种Android UI错误。我能够避免这种情况,所以我想分享解决方案。

问题本身是由ActionBar的导航引起的,原始设置是这样的。在res / menu / menu.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:title="@string/about"
        android:id="@+id/options_more"
        android:icon="@drawable/ic_baseline_more_vert_24px"
        android:orderInCategory="100"
        app:showAsAction="always" />
        <menu>
            <item
                android:id="@+id/anotherFragment"
                android:title="@string/another_menu_title" />

            <item
                android:id="@+id/alsoAnotherFragment"
                android:title="@string/alsoanother_menu_title" />
        </menu>
    </item>
</menu>

在这种情况下,如果单击右上角的菜单项,则会显示一个下拉菜单(其中包含两个以上的项)。

当我使用这种布局时,出现了滞后。经过数小时的反复试验,我将下拉菜单分为两个单独的按钮,如下所示:

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/anotherFragment"
        android:icon="@drawable/ic_baseline_location_city_24px"
        android:title="@string/about"
        app:showAsAction="ifRoom"/>
    <item
        android:id="@+id/alsoAnotherFragment"
        android:icon="@drawable/ic_baseline_more_vert_24px"
        android:title="@string/about"
        app:showAsAction="ifRoom"/>
</menu>

因此下拉菜单已关闭,问题现在消失了。一切正常,滞后消失了。我不是很了解问题的根源,但我认为它必须有某种解释。