0

J'ai ce problème pour accueillir mon bouton flottant, et je ne comprends pas pourquoi cela ne fonctionne pas. J'apprécierais votre réponse, car je ne peux pas trouver la raison pour laquelle cela se produit, un détail de plus lors du défilement ou du rechargement du fragment que certains des boutons flottants seront logés. Et désolé pour mon anglais.Ajouter un bouton flottant sur un CardView et RecyclerView

enter image description here

<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="wrap_content" 
android:background="@color/colorBackground" 
android:orientation="vertical"> 

<android.support.v4.widget.NestedScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/mRequestCard" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:elevation="100dp" 
     android:orientation="horizontal" 
     app:cardBackgroundColor="@color/colorWhite" 
     app:cardCornerRadius="3dp"> 

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

      <View 
       android:id="@+id/vDivisor" 
       android:layout_width="match_parent" 
       android:layout_height="2dp" 
       android:background="@color/colorGreen" /> 
        ... 

     </RelativeLayout> 

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

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


<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="30dp" 
    android:layout_height="30dp" 
    android:layout_marginRight="@dimen/fab_margin" 
    android:backgroundTint="@color/colorPurple" 
    android:scaleType="centerCrop" 
    android:src="@drawable/ic_route_direction" 
    app:layout_anchor="@id/mRequestCard" 
    app:layout_anchorGravity="right|end|bottom" /> 

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

Et voici ma RecyclerView qui est gonflé dans un fragment

<FrameLayout 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" 
tools:context="com.test.HistorialFragment"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <android.support.v7.widget.RecyclerView 
     android:id="@+id/mRecyclerRequest" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 
</FrameLayout> 

Et voici mon fragment, où je montre la RecyclerView

<FrameLayout 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/content_frame" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
app:layout_behavior="@string/appbar_scrolling_view_behavior" 
tools:context="com.test.MainActivity" 
tools:showIn="@layout/app_bar_main"> 
</FrameLayout> 
+0

Je pense que vous devriez essayer en flottant bouton android: layout_gravity = "bottom | end" –

Répondre

0

vous devriez essayez RelativeLayout comme ceci

<RelativeLayout android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:orientation="horizontal" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 
    <android.support.design.widget.FloatingActionButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:backgroundTint="@color/colorBlack" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true"/> 
    <android.support.v7.widget.CardView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:cardCornerRadius="@dimen/activity_corner" 
     android:layout_marginBottom="@dimen/activity_margin"> 
     <!--your cardview item here--> 
    </android.support.v7.widget.CardView> 
</RelativeLayout> 

pour votre RecyclerView article

0

Vérifiez si cela vous aide:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 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="wrap_content" 
    android:background="@color/colorPrimary" 
    android:orientation="vertical"> 

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.v7.widget.CardView 
      android:id="@+id/mRequestCard" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:elevation="100dp" 
      android:orientation="horizontal" 
      app:cardBackgroundColor="@color/colorWhite" 
      app:cardCornerRadius="3dp"> 

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

       <View 
        android:id="@+id/vDivisor" 
        android:layout_width="match_parent" 
        android:layout_height="2dp" 
        android:background="@color/colorGreen" /> 
       ... 

      </RelativeLayout> 

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

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


    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="30dp" 
     android:layout_height="30dp" 
     android:layout_alignParentRight="true" 
     android:layout_marginRight="10dp" 
     android:backgroundTint="@color/colorAccent" 
     android:scaleType="centerCrop" 
     android:src="@drawable/ic_launcher" 
     app:layout_anchor="@id/mRequestCard" 
     app:layout_anchorGravity="right|end|bottom" /> 

</RelativeLayout> 
0

essayer cette utilisation RelativeLayout et faites votre FloatingActionButtonpropriétéandroid:layout_alignParentBottom="true"et android:layout_alignParentRight="true" comme ci-dessous le code

<RelativeLayout android:layout_width="match_parent" 
android:layout_height="match_parent" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
android:orientation="horizontal" 
xmlns:android="http://schemas.android.com/apk/res/android"> 

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:backgroundTint="@color/colorBlack" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentRight="true"/> 
<android.support.v7.widget.CardView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:cardCornerRadius="@dimen/activity_corner" 
    android:layout_marginBottom="@dimen/activity_margin"> 


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

</RelativeLayout>