Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.12 KB | None | 0 0
  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:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="match_parent"
  6. xmlns:app="http://schemas.android.com/apk/res-auto"
  7. android:id="@+id/fabCoordinator"
  8. tools:context=".features.tasklist.TaskFragment">
  9. <android.support.v4.widget.SwipeRefreshLayout
  10. android:id="@+id/srTasks"
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content">
  13. <android.support.v7.widget.RecyclerView
  14. android:id="@+id/rvTask"
  15. android:layout_width="match_parent"
  16. android:layout_height="match_parent" />
  17. </android.support.v4.widget.SwipeRefreshLayout>
  18. <android.support.design.widget.FloatingActionButton
  19. android:id="@+id/fabAddTask"
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_marginBottom="0dp"
  23. android:layout_marginEnd="16dp"
  24. android:background="@color/colorAccent"
  25. android:src="@drawable/ic_plus"
  26. app:layout_anchor="@id/rvTask"
  27. android:layout_gravity="bottom|end"
  28. app:layout_anchorGravity="bottom|right|end"
  29. app:layout_behavior="com.example.qitment.todomanager.features.tasklist.ScrollAwareFABBehavior"
  30. />
  31. <LinearLayout
  32. android:layout_width="match_parent"
  33. android:layout_height="wrap_content"
  34. android:id="@+id/layoutFlower"
  35. android:orientation="vertical">
  36. <ImageView
  37. android:id="@+id/picFlower"
  38. android:layout_width="171dp"
  39. android:layout_height="143dp"
  40. android:layout_gravity="center_horizontal"
  41. android:layout_marginTop="40dp"
  42. android:src="@mipmap/pic_flower"/>
  43. <TextView
  44. android:layout_marginTop="36dp"
  45. android:gravity="center_horizontal"
  46. android:layout_width="match_parent"
  47. android:layout_height="wrap_content"
  48. android:layout_gravity="center_horizontal"
  49. android:textSize="16sp"
  50. android:textColor="@color/black_text_color"
  51. android:text="@string/you_do_all_label" />
  52. <TextView
  53. android:layout_marginTop="8dp"
  54. android:gravity="center_horizontal"
  55. android:layout_width="match_parent"
  56. android:layout_height="wrap_content"
  57. android:layout_gravity="center_horizontal"
  58. android:textSize="14sp"
  59. android:textColor="@color/grey_text_color"
  60. android:text="@string/have_a_nice_time" />
  61.  
  62. </LinearLayout>
  63.  
  64. </android.support.design.widget.CoordinatorLayout>
  65.  
  66.  
  67.  
  68.  
  69.  
  70. public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
  71. public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
  72. // This is mandatory if we're assigning the behavior straight from XML
  73. super();
  74. }
  75.  
  76. @Override
  77. public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View directTargetChild, final View target, final int nestedScrollAxes) {
  78. // Ensure we react to vertical scrolling
  79. return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
  80. || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
  81. }
  82.  
  83. @Override
  84. public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed,final int dxUnconsumed, final int dyUnconsumed) {
  85. super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
  86. if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
  87. // User scrolled down and the FAB is currently visible -> hide the FAB
  88. child.hide();
  89. } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
  90. // User scrolled up and the FAB is currently not visible -> show the FAB
  91. child.show();
  92. }
  93. }
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement