1

J'utilise mise en page du coordinateur, vue recycleur et bouton flottant. D'une certaine manière, le bouton fab ne reste pas au bas de la mise en page. Je voudrais que le bouton reste en bas même en faisant défiler. Ce que je sais, c'est que le bouton Fab prend la dernière position du dernier élément dans la vue recycleur.Comment puis-je faire en sorte que le bouton Flottant reste au bas de la mise en page?

enter image description here

liste-activity.xml

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      tools:listitem="@layout/activity_sample_05borangb_parent" 
      android:id="@+id/recyclerView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical"/> 

    </RelativeLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:foregroundGravity="bottom" 
     android:layout_gravity="bottom|end"/> 


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

Supprimer 'android: scrollbars' ou' Android: foregroundGravity' et un essai. – KeLiuyue

+0

@KeLiuyue je l'ai essayé ... mais le bouton planait toujours au milieu de la mise en page – xxmilcutexx

Répondre

3

enter image description here

Essayez ceci:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical"/> 

    </RelativeLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:foregroundGravity="bottom" 
     android:layout_margin="16dp" 
     android:layout_gravity="bottom|end"/> 


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

cela ne fonctionne toujours pas ... le bouton est toujours affiché sur le bas de la liste au lieu de bas de la mise en page – xxmilcutexx

+0

montrez vos efforts. Expliquez où vous obtenez l'erreur @ Pritesh-ɥsǝʇᴉɹꓒ –

2

Faire les modifications suivantes

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

    <RelativeLayout 
     android:id="@+id/container" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerView2" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:scrollbars="vertical"/> 

    </RelativeLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:fabSize="normal" 
     app:layout_anchor="@id/container" 
     app:layout_anchorGravity="bottom|end"/> 


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

Vous devez spécifier un layout_anchor et layout_anchorGravity

+0

Je l'ai essayé ... ça ne marche pas. Le bouton prend toujours le bas de la vue Recycleur au lieu du bas de la mise en page. – xxmilcutexx

2

Vous n'avez pas besoin d'utiliser android.support.design.widget.CoordinatorLayout pour réaliser cette mise en page relative est plus que suffisant.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

     <android.support.v7.widget.RecyclerView 
      tools:listitem="@layout/activity_sample_05borangb_parent" 
      android:id="@+id/recyclerView2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" /> 

    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" /> 

</RelativeLayout> 
+0

depuis mon recycleurView a deux éléments ... le bouton flottant apparaît toujours au bas du dernier élément, plutôt la mise en page bas – xxmilcutexx

+0

Je pense que la réponse ci-dessus devrait fonctionner pour vous S'il vous plaît essayez et laissez-moi savoir les résultats. –