2

我正在使用带有 AppBarLayout 的布局,其中包含 Toolbar 和 TabLayout、ViewPager 和 FloatingActionMenu。

我的问题是,当使用 layout_height=match_parent 时,使用 AppBarLayout 会导致 CoordinatorLayout 内的其他视图与整个屏幕不匹配,而是与父级的剩余视图匹配,不包括 AppBarLayout。这种行为对我的 ViewPager 来说是完美的,因为否则它的内容会被 AppBarLayout 覆盖,但我需要 FloatingActionMenu 来匹配整个屏幕,这样当我的菜单打开时我可以使屏幕变暗。

所以我的问题是:我怎样才能让我的 FloatingActionMenu 占据整个屏幕?

我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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="com.example.Home">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppBaseTheme.ToolbarPopup"
        app:theme="@style/AppBaseTheme.Toolbar">

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        app:tabTextAppearance="@style/AppBaseTheme.TabText"
        app:theme="@style/AppBaseTheme.Toolbar"/>

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:id="@+id/home_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<com.example.FloatingActionMenu
    android:id="@+id/fam"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="bottom|end"
    android:padding="@dimen/fab_margin"
    app:menu_backgroundColor="#BB8b8b8b">

    <com.example.FloatingActionButton
        android:id="@+id/fab"
        style="@style/MenuButtonsStyle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</com.example.FloatingActionMenu>

使用 RelativeLayout 作为我的根视图或使用 LinearLayout 来保存我的 Toolbar 和 TabLayout 可以解决我的问题,但我需要使用 CoordinatorLayout 和 AppBarLayout 来添加滚动功能。

编辑:

在不同的设备上进行测试后,我发现这个问题只发生在较新的版本上,你可以在下一张照片中看到。

在 API 19 上: 旧版本:API 19

在 API 23 上:

较新版本:API 23

4

1 回答 1

2

问题是我没有为我的 FloatingActionMenu 指定 android:elevation,所以 AppBarLayout 出现在菜单的顶部

于 2016-01-10T01:27:28.960 回答