Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:id="@+id/fabCoordinator"
- tools:context=".features.tasklist.TaskFragment">
- <android.support.v4.widget.SwipeRefreshLayout
- android:id="@+id/srTasks"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/rvTask"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- </android.support.v4.widget.SwipeRefreshLayout>
- <android.support.design.widget.FloatingActionButton
- android:id="@+id/fabAddTask"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="0dp"
- android:layout_marginEnd="16dp"
- android:background="@color/colorAccent"
- android:src="@drawable/ic_plus"
- app:layout_anchor="@id/rvTask"
- android:layout_gravity="bottom|end"
- app:layout_anchorGravity="bottom|right|end"
- app:layout_behavior="com.example.qitment.todomanager.features.tasklist.ScrollAwareFABBehavior"
- />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/layoutFlower"
- android:orientation="vertical">
- <ImageView
- android:id="@+id/picFlower"
- android:layout_width="171dp"
- android:layout_height="143dp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="40dp"
- android:src="@mipmap/pic_flower"/>
- <TextView
- android:layout_marginTop="36dp"
- android:gravity="center_horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:textSize="16sp"
- android:textColor="@color/black_text_color"
- android:text="@string/you_do_all_label" />
- <TextView
- android:layout_marginTop="8dp"
- android:gravity="center_horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:textSize="14sp"
- android:textColor="@color/grey_text_color"
- android:text="@string/have_a_nice_time" />
- </LinearLayout>
- </android.support.design.widget.CoordinatorLayout>
- public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior {
- public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
- // This is mandatory if we're assigning the behavior straight from XML
- super();
- }
- @Override
- public boolean onStartNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View directTargetChild, final View target, final int nestedScrollAxes) {
- // Ensure we react to vertical scrolling
- return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL
- || super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes);
- }
- @Override
- public void onNestedScroll(final CoordinatorLayout coordinatorLayout, final FloatingActionButton child, final View target, final int dxConsumed, final int dyConsumed,final int dxUnconsumed, final int dyUnconsumed) {
- super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
- if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) {
- // User scrolled down and the FAB is currently visible -> hide the FAB
- child.hide();
- } else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) {
- // User scrolled up and the FAB is currently not visible -> show the FAB
- child.show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement