2

我正在使用包含工具栏和TabLayout,ViewPager和FloatingActionMenu的AppBarLayout的布局。AppBarLayout不允许其他视图match_parent

我的问题是,当使用layoutBheight = 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来握住我的工具栏和TabLayout会解决我的问题,但我需要使用CoordinatorLayout和AppBarLayout添加滚动功能。

编辑:

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

在API 19: Older version: API 19

在API 23:

Newer version: API 23

+0

idk你的代码似乎是正确的,但是我可以删除这条线,为了调试,因为它不是真的需要! 'android:orientation =“vertical”'from appsbar – k0sh

+0

@ k0sh谢谢,我忘了删除它,在我尝试使用LinearLayout而不是AppBarLayout时使用它。 – colo99

回答

2

的问题是,我并没有指定一个机器人:我FloatingActionMenu抬高,所以AppBarLayout是出现在菜单顶部

相关问题