SupportMapFragment和DrawerLayout在一个AppCompatActivity中(SupportMapFragment and DrawerLayout in one AppC

编程入门 行业动态 更新时间:2024-10-28 02:25:20
SupportMapFragment和DrawerLayout在一个AppCompatActivity中(SupportMapFragment and DrawerLayout in one AppCompatActivity)

我的等级:

<android.support.v4.widget.DrawerLayout <android.support.v7.widget.Toolbar <fragment "com.google.android.gms.maps.SupportMapFragment" <android.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.android.gms.maps.SupportMapFragment

评论出地图或导航抽屉应用程序后,开始正常工作。

如何在一个Activity制作SupportMapFragment和DrawerLayout ,以及这个DrawerLayout的原因是什么?

My hierarchy:

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

Exception:

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.android.gms.maps.SupportMapFragment

After commenting out map or navigation drawer app start working correctly.

How to make SupportMapFragment and DrawerLayout in one Activity and what is the reason for this exeption?

最满意答案

使用这种方式:

我的build.gradle的依赖部分:

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' }

activity_main.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>

Use this Way :

Dependency section of my build.gradle :

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' }

activity_main.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>

更多推荐

本文发布于:2023-07-15 11:05:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1112871.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SupportMapFragment   DrawerLayout   AppCompatActivity

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!