【发布时间】:2016-03-30 03:28:32
【问题描述】:
我正在开发一个 Android 应用程序。在我的应用程序中,我使用抽屉布局作为主要布局。主要内容的抽屉布局内有一个框架布局。单击项目表单抽屉时,主要内容将替换为片段。 Fragment 可以包含 listview、scroll、gridview 等等。
我想要的是固定在屏幕右下方的浮动操作按钮。那必须在主布局(DrawerLayout)中,因为它将包含所有被替换的片段。我在主布局中添加了一个浮动操作按钮。但是当我运行我的应用程序时我看不到它。
这是主要的布局 XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- This LinearLayout represents the contents of the screen -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<!-- The ActionBar displayed at the top -->
<include
layout="@layout/action_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!-- The main content view where fragments are loaded -->
<FrameLayout
android:background="@color/whitesmoke"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.FloatingActionButton
android:layout_gravity="bottom|end"
android:id="@+id/fb_office_btn"
android:src="@android:drawable/ic_menu_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
app:itemIconTint="@drawable/drawer_item"
app:itemTextColor="@drawable/drawer_item"
android:id="@+id/left_nv_view"
app:headerLayout="@layout/header_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start" />
</android.support.v4.widget.DrawerLayout>
这是截图:
正如您在上面看到的,没有浮动操作按钮。我该如何解决?
编辑
当我将 LinearLayout 更改为 RelativeLayout 时,主要内容的 gridview 如下所示。操作栏消失了。
【问题讨论】:
标签: android