有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java SupportMapFragment和抽屉布局在一个AppCompative活动中

我的层次结构:

<安卓.support.v4.widget.DrawerLayout
   <安卓.support.v7.widget.Toolbar
      <fragment "com.google.安卓.gms.maps.SupportMapFragment"
<安卓.support.design.widget.NavigationView

例外情况:

Caused by: java.lang.IllegalArgumentException: Binary XML file line
#9: Duplicate id 0x7f0d007b, tag null, or parent id 0xffffffff with another fragment for com.google.安卓.gms.maps.SupportMapFragment

注释完地图或导航抽屉后,应用程序开始正常工作

如何将SupportMapFragmentDrawerLayout结合在一起Activity以及这种解释的原因是什么


共 (1) 个答案

  1. # 1 楼答案

    这样做:

    我的构建的依赖项部分。格拉德尔

     dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:23.0.0'
        compile 'com.google.android.gms:play-services:7.8.0'
        compile 'com.android.support:design:23.0.0'
    }
    

    主要活动。xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        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
            android:id="@+id/drawer"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    
        <FrameLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
                <fragment 
                     android:name="com.google.android.gms.maps.SupportMapFragment"
                     android:id="@+id/map"
                     android:layout_width="match_parent"
                     android:layout_height="match_parent"/>
    
                 <android.support.design.widget.FloatingActionButton
                    android:id="@+id/add"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_margin="16dp"
                    android:clickable="true"
                    android:src="@drawable/ic_maps_navigation"
                    app:backgroundTint="#777"
                    android:layout_gravity="bottom|end"/>
    
            </FrameLayout>
    
            <FrameLayout
                android:id="@+id/nav_container"
                android:layout_gravity="start"
                android:layout_width="240dp"
                android:layout_height="fill_parent"/>
    
        </android.support.v4.widget.DrawerLayout>
    
    </RelativeLayout>