无法使用 RecyclerView 在 header 和 DrawerLayout 中的项目之间放置浮动操作按钮 (FAB)

Can't place Floating Action Button (FAB) between header and items in DrawerLayout using RecyclerView

我无法让浮动操作按钮 (FAB) 出现在正确的位置。我希望它出现在 header 和我的导航抽屉中的第一项之间。

目前,我让它出现在 header 的右下角,而不是在第一个和第二个元素之间的线的顶部(第一个元素 = header & 第二个element = recyclerview 中的第一项)。

我的应用正在使用以下应用兼容项:

我正在使用导航抽屉,但我无法使用 NavigationView,因为我需要自定义项目条目而不是加载简单菜单。

如你所知,抽屉真的不是2个不同的控件。 header 实际上是 RecyclerView 中的“0”元素。我不知道这是否有所作为。

这是我当前 xml 的 header/“RecyclerView 中的 0 视图”:

     <?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"
    android:layout_width="match_parent"
    android:layout_height="@dimen/navdrawer_image_height">


    <RelativeLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/navDrawerHeaderView"
        android:layout_width="match_parent"
        android:layout_height="@dimen/navdrawer_image_height">

        <ImageView
            android:id="@+id/navdrawer_image"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/navdrawer_image_height"
            android:contentDescription="@string/cd_navdrawer_image"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_material_design" />

        <de.hdodenhof.circleimageview.CircleImageView
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/app_image"
            android:layout_width="@dimen/navdrawer_user_picture_size"
            android:layout_height="@dimen/navdrawer_user_picture_size"
            android:src="@drawable/ic_launcher"
            android:layout_marginTop="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            app:border_width="2dp"
            app:border_color="#FF000000"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/appNameTextView"
            android:text="App Name"
            android:textStyle="bold"
            android:layout_marginLeft="16dp"
            android:layout_marginStart="16dp"
            android:layout_marginBottom="16dp"
            android:layout_alignParentBottom="true"
            android:textColor="@android:color/white"/>

    </RelativeLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:src="@drawable/button_account"
        app:layout_anchor="@id/navDrawerHeaderView"
        app:layout_anchorGravity="bottom|right|end"
        app:elevation="4dp"/>

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

我想我可能把 FAB 弄错了 location/file。这是抽屉的 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/drawerLayout"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:fitsSystemWindows="true">

    <!-- Content layout -->
    <LinearLayout
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/toolbar"
            layout="@layout/tool_bar"/>

        <FrameLayout
            android:id="@+id/contentFrame"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/init_background">
        </FrameLayout>

    </LinearLayout>

    <!-- Pages -->
    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="320dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="#ffffff"
        android:scrollbars="vertical"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true">

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

</android.support.v4.widget.DrawerLayout>

帮助!!!!!

示例抽屉片段布局包含您现有的 RecyclerView:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="200dp">
        <View
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#f00"
            android:id="@+id/header"/>
    </android.support.design.widget.AppBarLayout>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        android:scrollbars="vertical"
        android:clickable="true"
        android:focusable="true"
        android:focusableInTouchMode="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

    <android.support.design.widget.FloatingActionButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        app:layout_anchor="@id/appbar"
        app:layout_anchorGravity="bottom|right|end"
        android:layout_margin="5dp"
        android:clickable="true"/>

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