【问题标题】:Unable to pin FloatingActionButton when Toolbar collapse工具栏折叠时无法固定 FloatingActionButton
【发布时间】:2018-01-09 07:45:24
【问题描述】:

我在 viewpager 中有片段,所以片段由 Recyclerview 和 FloatingActionButton 组成。因此,当我滚动 recyclerview 时,工具栏折叠和 tablayout 引脚,但浮动操作按钮也会向上滚动。我想将 FlootingActionButton 固定到它的位置。

请检查图片 -

现在,当我滚动工具栏折叠时,浮动操作按钮也会向上移动。 -

请告诉我如何将 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> 

【问题讨论】:

  • 尝试将 fab 锚点更改为:@+id/coordinatorLayout
  • @BrunoFerreira 这不起作用。说视图不能锚定到父布局。

标签: android android-recyclerview android-toolbar floating-action-button coordinator-layout


【解决方案1】:

试试这个:

<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" />

【讨论】:

  • 仍然无法正常工作。 FAB 仍然上下滚动
猜你喜欢
  • 1970-01-01
  • 2016-04-20
  • 1970-01-01
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
  • 2015-08-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多