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
<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>
Je pense que vous devriez essayer en flottant bouton android: layout_gravity = "bottom | end" –