首页 > 解决方案 > 如果在消失模式下准备好,谷歌地图 v2 就会消失

问题描述

我在 mapFragment 视图中准备的 mapFragment 视图有问题visibility=View.GONE

在准备(getMapAsync调用)visibility=View.VISIBLE状态时它可以正常工作,但如果在准备时它会变为空白GONE

mapFragmenta 中查看ScrollView(它是较长列表的一部分),并且对滚动处理进行了一些小的调整,它可以完美地工作。

我有一个longClickListener定义来捕捉 a 的 lat/lng 对,当地图以模式longClick准备时,这工作正常VISIBLE,但是当它以GONE模式准备时,(空白地图)给我 0.0,0.0 lat/lng 结果,这告诉我那是地图不“存在”,(它不是导致这种行为的任何图形抽搐)。

空白地图,在 GONE 时创建

下面是在VISIBLE模式下准备的地图

在可见模式下准备的工作地图

即使在什么时候准备好地图也不应该出现GONE,还是我需要做一些其他的伎俩。


                <androidx.appcompat.widget.LinearLayoutCompat
                    android:id="@+id/register_card_linear_layout_compat_common_selections"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:visibility="visible"    <--- toggle to `gone` here cause map to not appear when made visible programmatically
                    tools:visibility="visible"
                    android:orientation="vertical">

...

                            <androidx.constraintlayout.widget.ConstraintLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">

                                <androidx.fragment.app.FragmentContainerView
                                    android:id="@+id/register_card_map_fragment"
                                    android:name="no.norva24.mslam.ui.fragments.customizations.ScrollableMapFragment"
                                    android:layout_width="match_parent"
                                    android:layout_height="0dp"
                                    app:layout_constraintBottom_toBottomOf="parent"
                                    app:layout_constraintDimensionRatio="1:1"
                                    app:layout_constraintEnd_toEndOf="parent"
                                    app:layout_constraintHorizontal_bias="0.0"
                                    app:layout_constraintStart_toStartOf="parent"
                                    app:layout_constraintTop_toTopOf="parent"
                                    app:layout_constraintVertical_bias="0.0"
                                    tools:context=".ui.fragments.RegisterFragment" />





地图在里面准备的地方onViewCreated



        mapFragment?.getMapAsync {_googleMap->

            Log.i(TAG, "onViewCreated: mapFragment getMapAsync _googleMap =$_googleMap")

            _googleMap?.let {safeGoogleMap->
                googleMap=safeGoogleMap

   

LogCat 告诉我,即使地图处于状态,也会getMapAsync以有效的方式调用..._googleMapGONE

标签: androidkotlingoogle-maps-android-api-2mapfragment

解决方案


推荐阅读