无法在工具栏折叠时固定FloatingActionButton

问题描述:

我在viewpager内部有片段,所以片段由Recyclerview和FloatingActionButton组成。所以当我滚动recyclerview工具栏折叠和tablayout引脚,但浮动操作按钮也滚动。我想将FlaotingActionButton固定到它的位置。无法在工具栏折叠时固定FloatingActionButton

请检查图像 - Initial position of FloatingActionButton

现在,当我滚动栏collpase和floatingactionbutton也向上移动。 - FloatingActionButton moves up.

请让我知道如何将FloatingActionButton固定在右下方。

氏是XML文件 -

<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:id="@+id/coordinatorLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    android:fitsSystemWindows="true"> 

<android.support.v7.widget.RecyclerView 
    android:id="@+id/recycler_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/md_grey_200" /> 

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="16dp" 
    android:src="@drawable/ic_calendar_icon" 
    app:backgroundTint="@color/primary" 
    app:elevation="2dp" 
    app:fabSize="normal" 
    app:layout_anchor="@+id/recycler_view" 
    app:layout_anchorGravity="bottom|right|end" 
    app:layout_dodgeInsetEdges="right|bottom|top|left" 
    app:layout_insetEdge="bottom" 
    app:pressedTranslationZ="12dp" /> 


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

尝试改变晶圆厂锚这样:@ + ID/coordinatorLayout –

+0

@BrunoFerreira并没有工作。说查看不能锚定到父级布局。 – rahul

试试这个:

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/fab" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginRight="16dp" 
    android:src="@drawable/ic_calendar_icon" 
    app:backgroundTint="@color/primary" 
    app:elevation="2dp" 
    app:fabSize="normal" 
    android:layout_gravity="end|bottom" 
    app:layout_dodgeInsetEdges="right|bottom|top|left" 
    app:layout_insetEdge="bottom" 
    app:pressedTranslationZ="12dp" /> 
+0

仍然无法正常工作。 FAB仍然上下滚动 – rahul