【问题标题】:NavigationDrawer behind MapFragmentMapFragment 后面的 NavigationDrawer
【发布时间】:2014-01-16 20:05:25
【问题描述】:

[已解决] 我将此添加到 MainActivity XML 文件中:

<FrameLayout
    android:id="@+id/place_map_here"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>
<FrameLayout
    android:id="@+id/bugfixview"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:background="@android:color/transparent"/>

以及我更改片段的位置:

mapFragment = new FragmentMapView();
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.add(R.id.place_map_here, mapFragment, "map");
ft.commit();

编辑:刚刚意识到我不使用 MapFragment xml 文件。(旧版本很抱歉)

我已将 Fragment 更改为 MapFragment,现在我的 NavigationDrawer 滑入 MapFragment 后面 :( 代码:

MapFragmant xml(已删除代码)

MainActivity xml。这是我的抽屉声明

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >


<android.support.v4.widget.DrawerLayout         xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>
<ListView
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:background="#333"
    android:choiceMode="singleChoice"/>
</android.support.v4.widget.DrawerLayout>    
</RelativeLayout>

我希望这是您需要的信息,让您像往常一样出色并帮助像我这样的菜鸟:)

【问题讨论】:

标签: android google-maps navigation-drawer mapfragment


【解决方案1】:

试试这个技巧,它可能会对你有所帮助,只需将你的布局更改为如下所示:

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

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" >

    <android.support.v4.widget.DrawerLayout
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent" >


    <!-- hack to fix ugly black Background with maps v2 -->

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent" />
</FrameLayout>

</LinearLayout>

【讨论】:

    【解决方案2】:

    DrawerLayout 需要是您布局的根,因此请尝试删除 RelativeLayout。我假设您将 MapFragment 附加到 FrameLayout,main。

    另外,您使用的是哪个 api 版本?我注意到 api

    【讨论】:

      【解决方案3】:

      我们可以通过使用布局中地图片段正下方的视图来解决 NavigationDrawer 落后于 MapFragment 的问题。

      例如 -

      <FrameLayout
          android:id="@+id/root"
          android:layout_width="match_parent"
          android:layout_height="match_parent" >
      
          <fragment
              android:id="@+id/map"
              android:layout_width="match_parent"
              android:layout_height="match_parent"      
              class="com.google.android.gms.maps.SupportMapFragment" />
      
      
      <View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多