[已解决] 我将其添加到 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"/>
以及我更改 fragment 的位置:
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(删除代码)
主要 Activity 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>
我希望这是您需要的信息,让您一如既往地出色并帮助像我这样的菜鸟:)
最佳答案
试试这个 hack 它可能对你有帮助,只需将你的布局更改为如下所示:
<?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>
关于android - MapFragment 后面的 NavigationDrawer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20948557/