0

Ich habe eine Anwendung mit einer Hauptaktivität und einige Fragment, jedes Fragment ist ein Listenfragment, aber in einigen von ihnen muss ich ein FloatingActionButton mit einer benutzerdefinierten Aktion hinzufügen, und ich möchte den automatisch generierten Adapter für diese Liste beibehalten. Wenn ich den FloatingActionButton direkt zu der XML-Liste hinzufügen, wie kann ich die Schaltfläche hinzufügen?Schwimmende Schaltfläche unter Listview in Fragmentliste hinzufügen

Das ist mein Fragment xml Code

<?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> 

Und ich habe versucht, die FloatingActionButton auf diese Weise

<?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> 

Antwort

1
<?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> 
hinzufügen
Verwandte Themen