片段列表listview下添加浮动按钮

Add floating button under listview in fragment list

我有一个包含一个主 activity 和一些片段的应用程序,每个片段都是一个列表片段,但是,在其中一些片段中,我需要添加一个带有自定义操作的 FloatingActionButton,我想保留该列表的自动生成的适配器。 如果我将 FloatingActionButton 直接添加到 xml 列表消失器,我该如何添加按钮?

这是我的片段xml代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 
    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:id="@+id/list"
    android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
    tools:listitem="@layout/fragment_player" >

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

我试过用这种方式添加 FloatingActionButton

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView 
    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:id="@+id/list"
    android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    app:layoutManager="LinearLayoutManager"
    tools:context="it.ivannotarstefano.cojule.activity.PlayerFragment"
    tools:listitem="@layout/fragment_player" >

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="10dp"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/ic_add_black_24dp"
        app:backgroundTint="#fff700" />

</android.support.v7.widget.RecyclerView>
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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="match_parent">

    <android.support.v7.widget.RecyclerView 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:id="@+id/list"
        android:name="it.ivannotarstefano.cojule.activity.PlayerFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="16dp"
        app:layoutManager="LinearLayoutManager" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="10dp"
        android:baselineAlignBottom="true"
        android:clickable="true"
        android:focusable="true"
        android:src="@drawable/side_nav_bar"
        app:backgroundTint="#fff700" />

</FrameLayout>