【发布时间】:2016-01-21 16:39:01
【问题描述】:
我正在尝试在 CoordinatorLayout 中添加 FAB、MapView、工具栏和 DrawerLayout。我的地图视图将覆盖整个屏幕,FAB 将放置在地图视图上。我已经实现了一切,但问题在于地图视图。我无法与之互动。此外,当我打开抽屉时,它会低于 FAB 并且用户可以与它进行交互,这是我不想要的。
以下是我的 xml 代码。
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
android:fitsSystemWindows="true"
tools:context=".MainActivity">
<com.google.android.gms.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
app:layout_anchor="@+id/navigation_drawer"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.v4.widget.DrawerLayout
android:id="@id/navigation_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorAccent"
app:popupTheme="@style/AppTheme.PopupOverlay"
tools:showIn="@layout/activity_map_view">
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/app_name"
android:textSize="18sp" />
</android.support.v7.widget.Toolbar>
</LinearLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/navigation_items" />
</android.support.v4.widget.DrawerLayout>
<RelativeLayout
android:id="@+id/fab_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="40dp">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab3"
style="@style/floating_action_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@android:drawable/ic_dialog_email"
app:fabSize="mini" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab2"
style="@style/floating_action_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@id/fab3"
android:src="@android:drawable/ic_menu_week"
app:fabSize="mini" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab1"
style="@style/floating_action_button"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@id/fab2"
android:src="@drawable/cast_ic_notification_1"
app:fabSize="mini" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/floating_action_button"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_below="@id/fab1"
android:src="@drawable/ic_plusone_medium_off_client"
app:backgroundTint="#00FF00"
app:fabSize="normal" />
</RelativeLayout>
此外,当我将 DrawerLayout 的可见性设置为“消失”时,我可以与地图进行交互,这表明我的 DrawerLayout 位于地图视图之上,我无法摆脱它。
我的 XML 有什么问题吗?附件是我的抽屉打开和关闭时的屏幕截图。
提前致谢。
【问题讨论】:
-
你能张贴一张它应该是什么样子的截图吗(可能来自棒棒糖之前的设备)。另外,我怀疑您是否希望在 appbar 中有 mapView,因为 appbar 通常用于工具栏和 TabLayouts 之类的东西。
-
@G.deWit 感谢您的评论。从 AppBarLayout 中删除了地图视图,它适用于所有设备。
-
@G.deWit 但是现在我的导航栏在棒棒糖之前的设备上不可见。
-
您能否将您的 xml 更新为现在的样子。这是你唯一改变的东西吗?
-
@G.deWit 更新了 XML。我的应用栏现在可见。
标签: android android-layout android-5.0-lollipop floating-action-button android-coordinatorlayout