Android MapView 与 DrawerLayout 重叠

12

我有一个简单的布局结构:

DrawerLayout
\-- FrameLayout // @+id/fragment_container
\-- ListView    // @+id/drawer_list
通过点击任何抽屉项,我使用FragmentTransaction.replace()将相应的Fragment实例插入/替换到R.id.fragment_container中。其中一个Fragment包含一个MapView

不同设备上都存在渲染问题,但同时DDMS向我展示了正确的截图。

已编辑

此问题出现在以下设备上:

  • Huawei U9508,Android 4.0.4(API 15)
  • HTC Desire A9191,Android 2.3.5(API 10)

以下设备没有问题:

  • Samsung Galaxy S2,带有CyanogenMod Android 4.2.2(API 17)
  • LG Google Nexus 4,Android 4.3(API 18)

有谁能帮我理解并解决这个问题吗?

请参见下面的图片:

Huawei U9508,Android 4.0.4(API 15)

enter image description hereenter image description hereenter image description here

HTC Desire A9191,Android 2.3.5(API 10)

enter image description here

DDMS

enter image description here

已编辑

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/drawer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    <!-- The main content view -->
    <FrameLayout
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    <!-- The navigation drawer -->
    <ListView
            android:id="@+id/drawer_list"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            />
</DrawerLayout>

碎片布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

    <!-- other views here -->

    <com.google.android.gms.maps.MapView
            android:id="@+id/consumer_profile_map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
</RelativeLayout>

你是什么意思?如何避免这种情况发生? - Oleksii K.
抱歉打扰,你来自纽伦堡吗? - A.S.
你能展示一下你的XML布局吗? - A.S.
1个回答

31

所以,我找到了解决方法:只需将 MapView 包裹在容器中,并在上面放置一个空的 View。感谢此答案:https://dev59.com/WmUp5IYBdhLWcg3wNVhb#16231935

这是我的更新布局:

<FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    <com.google.android.gms.maps.MapView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />

    <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            />
</FrameLayout>

非常感谢,这也帮助了我解决类似的问题,但我使用的是VideoView而不是MapView。 - Sebastien Kovacs
还适用于 ru.yandex.yandexmapkit.MapView。一个简单而优雅的解决方案! - kit
同时修复了 com.mapbox.mapboxsdk.maps.MapView 中相同的问题。谢谢。 - stone

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接