【问题标题】:Android GoogleMap overlaps Views onResumeAndroid GoogleMap 重叠 Views onResume
【发布时间】:2014-04-11 18:57:47
【问题描述】:

我在RelativeLayout 中显示GoogleMap,并在上方显示TextView(除其他外):

<RelativeLayout
    width=match_parent
    height=match_parent>
    <Map
        width=match_parent
        height=match_parent />
    <TextView
        with=100dp
        height=100dp />
</RelativeLayout>

出于某种原因,如果我回到家,然后重新打开应用程序,地图将覆盖(覆盖)TextView

我尝试使用SupportMapFragmentMapView(与zOrderOnTop="false")但没有效果。 我也尝试在onResume/onPause中显示/隐藏地图,没有效果。

我也有Drawer issue,但建议的修复只解决了Drawer 问题。

版本: com.google.android.gms:play-services:4.2.+ compileSdkVersion 19 minSdkVersion 14 targetSdkVersion 14.

注意:此问题仅在三星 Galaxy SII (4.0.4) 上出现。 任何想法?谢谢。

更新:我也尝试从代码中扩充Fragment 而不是XML,或者使用GoogleMapOptions 设置zOrderOnTop(false),结果还是一样...

更新 2:我想我缩小了问题范围:

工作:

抽屉.xml

<Drawer>
    <RelativeLayout
        width=match_parent
        height=match_parent>
        <RelativeLayout
            width=match_parent
            height=match_parent>
            <Map
                width=match_parent
                height=match_parent>
            <View
                width=match_parent
                height=match_parent
                background=transparent>
        </RelativeLayout>

        <TextView
            width=100dp
            height=100dp>
    </RelativeLayout>

    <ListView /> <!-- menu -->
</Drawer>

不工作:

抽屉.xml

<Drawer>
    <FrameLayout /> <!-- fragment container -->

    <ListView /> <!-- menu -->
</Drawer>

map.xml

<RelativeLayout
    width=match_parent
    height=match_parent>
    <RelativeLayout
        width=match_parent
        height=match_parent>
        <Map
            width=match_parent
            height=match_parent>
        <View
            width=match_parent
            height=match_parent
            background=transparent>
    </RelativeLayout>

    <TextView
        width=100dp
        height=100dp>
</RelativeLayout>

一种解决方案是在drawer.xml 中声明地图,然后在需要时使用setVisibility 显示/隐藏它...有更好的建议吗?

【问题讨论】:

    标签: android google-maps overlay google-maps-android-api-2


    【解决方案1】:

    你应该试试:

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_width="match_parent">
    
        <!-- Extra hack ViewGroup to fix Map z-ordering -->
        <RelativeLayout 
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
    
            <Map
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
    
            <View 
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"/>
    
        </RelativeLayout>
    
        <TextView
            with=100dp
            height=100dp />
    
    </RelativeLayout>
    

    至少对我来说,这足以解决 z 顺序的问题。我相信这个问题只会影响之前的 Jellybean 设备,这就解释了为什么你会在 SII 上看到它。

    【讨论】:

    • 谢谢,但我已经尝试过了。它只解决了抽屉问题,而不是主要问题...
    猜你喜欢
    • 1970-01-01
    • 2021-10-06
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多