android – 滚动感知FAB隐藏,但后来不再出现

前端之家收集整理的这篇文章主要介绍了android – 滚动感知FAB隐藏,但后来不再出现前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我制作了一个带有recyclerview和浮动动作按钮的 Android应用程序.向下滚动时,按钮应隐藏,向上滚动时应再次显示.我用 this tutorial来实现这个行为.

结果是,当我向下滚动时FAB隐藏,但是当向上滚动时它不会再次出现:(类ScrollAwareFABBehavior与教程相同.但我使用的是嵌套布局.

这是我的布局(recyclerview位于content_main的LinearLayout中):

  1. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. xmlns:app="http://schemas.android.com/apk/res-auto"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. android:fitsSystemWindows="true"
  7. tools:context="org.myorganisation.mypackage.someActivity">
  8.  
  9. <include layout="@layout/toolbar" />
  10.  
  11. <include layout="@layout/content_main" />
  12.  
  13. <android.support.design.widget.FloatingActionButton
  14. android:id="@+id/add_fab"
  15. android:layout_width="wrap_content"
  16. android:layout_height="wrap_content"
  17. android:layout_gravity="bottom|end"
  18. android:layout_margin="@dimen/fab_margin"
  19. android:src="@drawable/plus"
  20. app:layout_behavior="org.myorganisation.mypackage.someActivity.helpers.ScrollAwareFABBehavior" />
  21.  
  22. <LinearLayout
  23. android:id="@+id/insert_alert"
  24. android:layout_width="wrap_content"
  25. android:layout_height="50sp"
  26. android:layout_margin="@dimen/fab_margin"
  27. android:gravity="center_vertical"
  28. android:orientation="horizontal"
  29. android:paddingEnd="70sp"
  30. android:visibility="gone"
  31. app:layout_anchor="@id/add_fab"
  32. app:layout_anchorGravity="bottom|left">
  33.  
  34. <TextView
  35. android:layout_width="wrap_content"
  36. android:layout_height="wrap_content"
  37. android:gravity="center_vertical"
  38. android:text="@string/initial_alert"
  39. android:textColor="@color/colorPrimaryDark"
  40. android:textStyle="bold|italic" />
  41.  
  42. <ImageView
  43. android:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:src="@drawable/ic_keyboard_arrow_right_black_24sp"
  46. android:tint="@color/colorPrimary" />
  47. </LinearLayout>
  48.  
  49. </android.support.design.widget.CoordinatorLayout>

解决方法

支持库的25.1.0版开始,隐藏视图不再按照 this bug滚动事件.

comment #5所述:

This is working as intended,your dependency chain is the wrong way. Your RecyclerView (Behavior) should be triggering the FAB visibility change.

猜你在找的Android相关文章