android – 折叠折叠工具栏时隐藏浮动按钮

前端之家收集整理的这篇文章主要介绍了android – 折叠折叠工具栏时隐藏浮动按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个协调器布局,包含一个折叠工具栏,一个嵌套的滚动视图和一个浮动按钮.
我的浮动按钮位于折叠工具栏的右下端.我希望折叠工具栏完全折叠时按钮消失.在其他情况下可见.

我的xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:fitsSystemWindows="true"
  8. tools:context="fr.djey.secretapp.MainActivity">
  9.  
  10. <android.support.design.widget.AppBarLayout
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content"
  13. android:theme="@style/AppTheme.AppBarOverlay"
  14. android:id="@+id/appBar">
  15.  
  16. <android.support.design.widget.CollapsingToolbarLayout
  17. android:id="@+id/collapse_toolbar"
  18. android:layout_width="match_parent"
  19. android:layout_height="match_parent"
  20. app:layout_scrollFlags="scroll|exitUntilCollapsed"
  21. android:fitsSystemWindows="true"
  22. app:contentScrim="?attr/colorPrimary"
  23. app:expandedTitleMarginStart="48dp"
  24. app:expandedTitleMarginEnd="64dp">
  25.  
  26. <ImageView
  27. android:id="@+id/collapsing_image"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:fitsSystemWindows="true"
  31. app:layout_collapseMode="parallax"
  32. android:scaleType="centerCrop"
  33. android:src="@drawable/welcome"/>
  34.  
  35. <android.support.v7.widget.Toolbar
  36. android:id="@+id/toolbar"
  37. android:layout_width="match_parent"
  38. android:layout_height="?attr/actionBarSize"
  39. app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
  40. app:layout_collapseMode="pin"/>
  41.  
  42. </android.support.design.widget.CollapsingToolbarLayout>
  43.  
  44. </android.support.design.widget.AppBarLayout>
  45.  
  46. <android.support.v4.widget.NestedScrollView
  47. android:layout_width="match_parent"
  48. android:layout_height="match_parent"
  49. xmlns:tools="http://schemas.android.com/tools"
  50. android:layout_gravity="fill_vertical"
  51. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  52. xmlns:android="http://schemas.android.com/apk/res/android"
  53. xmlns:app="http://schemas.android.com/apk/res-auto">
  54.  
  55. <FrameLayout
  56. android:layout_width="match_parent"
  57. android:layout_height="match_parent"
  58. android:id="@+id/content_frame">
  59.  
  60. </FrameLayout>
  61.  
  62. </android.support.v4.widget.NestedScrollView>
  63.  
  64. <android.support.design.widget.FloatingActionButton
  65. android:id="@+id/fab"
  66. android:layout_width="wrap_content"
  67. android:layout_height="wrap_content"
  68. android:layout_marginTop="-60dp"
  69. android:layout_marginRight="16dp"
  70. android:src="@android:drawable/ic_dialog_email"
  71. app:layout_anchor="@id/collapse_toolbar"
  72. app:layout_anchorGravity="bottom|right|end" />
  73.  
  74. </android.support.design.widget.CoordinatorLayout>

有可能吗?怎么样?

解决方法

尝试这个小改动
  1. <android.support.design.widget.FloatingActionButton
  2. ...
  3. app:layout_anchor="@id/appBar"
  4. app:layout_anchorGravity="bottom|right|end" />

猜你在找的Android相关文章