0

J'ai un fragment qui rend un recycleview avec un buttom d'action flottant. Le problème est que lorsque la liste est vide, l'usine reste en haut à droite, quand la liste a peu d'éléments, l'usine conserve la liste ci-dessous mais pas en bas, et elle ne reste en bas que lorsque la liste remplit la liste. écran avec des éléments. Est-ce que quelqu'un pourrait m'aider s'il vous plaît? Bellow est mon code:Le bouton d'action flottante d'Android ne se fixe pas au fond

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.app.juninho.financeapp.activity.FuncionarioActivity"> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/btn_add_func" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right|end" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_menu_send" 
     app:layout_behavior="com.app.juninho.financeapp.utils.ScrollAwareFABBehavior" /> 

if the list is empty, fab keeps at the top, wich is wrongif the list has a few items, fab doesn't keep totaly at the bottom

Here is the correct way, fab is at the bottom

Using RelativeLayout it seems to work, but its too at the right/bottom corner

+0

Le problème est très probablement dans cette classe personnalisée : com.app.juninho.financeapp.utils.ScrollAwareFABBehavior – BladeCoder

+0

Salut BladeCoder! Merci pour votre réponse! Cette classe personnalisée ne fait que masquer le fab lors de la gravure de la liste et l'affiche lors de la scrolation. J'ai essayé d'enlever ceci mais le problème persiste ... –

+0

Pouvez-vous juste remplacer le CoordinatorLayout avec un Framelayout/RelativeLayout? –

Répondre

0

Le problème est votre FAB attribut: app:layout_behavior="com.app.juninho.financeapp.utils.ScrollAwareFABBehavior".

#. Vous n'avez pas besoin d'ajouter ceci avec votre FAB. Il suffit de supprimer cet attribut et d'ajouter l'attribut app:layout_anchor="@id/funcionario_recycler_view" et app:layout_anchorGravity="bottom|right|end" à FAB à anchor avec RecyclerView.

Mettez à jour votre mise en page comme ci-dessous:

<?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" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.app.juninho.financeapp.activity.FuncionarioActivity"> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/btn_add_func" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|right|end" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_margin="16dp" 
     android:src="@drawable/ic_menu_send" 
     app:layout_anchor="@id/funcionario_recycler_view" 
     app:layout_anchorGravity="bottom|right|end" /> 
</android.support.design.widget.CoordinatorLayout> 

#. Si vous voulez masquer/afficher FAB lors du défilement RecyclerView, vous pouvez le faire pragmatically dans votre code java comme ci-dessous:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.funcionario_recycler_view); 
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.btn_add_func); 

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() 
{ 
    @Override 
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) 
    { 
     if (dy > 0 ||dy<0 && fab.isShown()) 
     { 
      fab.hide(); 
     } 
    } 

    @Override 
    public void onScrollStateChanged(RecyclerView recyclerView, int newState) 
    { 
     if (newState == RecyclerView.SCROLL_STATE_IDLE) 
     { 
      fab.show(); 
     } 

     super.onScrollStateChanged(recyclerView, newState); 
    } 
}); 

Espérons que cela aidera ~

+0

RecyclerView ne bouge pas et le FAB doit rester en bas à droite de la mise en page, donc aucune ancre n'est nécessaire. – BladeCoder

+0

Oui, vous avez raison. L'ancre de mise en page n'est pas nécessaire ici. – FAT

+0

Salut les gars! Malheureusement, cela n'a pas fonctionné. Je suis sur le point d'abandonner ... Il garde le même comportement. J'ai oublié de dire que j'utilise cette recycleview et cette fab avec un fragment qui configure l'adaptateur recycleview dans son onViewCreate, et je n'utilise pas de snackbar. Mon application a une seule activité, qui contient un tiroir de navigation et FrameLayout qui montrent toute la disposition de mon fragment ... Y at-il autre chose que je peux faire? Merci beaucoup pour votre aide! –