show fab after delay when scroll is stopped
This commit is contained in:
parent
5bd10c4a1a
commit
55f36de34b
|
@ -12,11 +12,28 @@ import android.view.animation.LinearInterpolator;
|
|||
|
||||
public class FabScrollingBehavior extends CoordinatorLayout.Behavior<FloatingActionButton> {
|
||||
private static final String TAG = "ScrollingFABBehavior";
|
||||
Handler mHandler;
|
||||
|
||||
public FabScrollingBehavior(Context context, AttributeSet attrs) {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStopNestedScroll(CoordinatorLayout coordinatorLayout, final FloatingActionButton child, View target) {
|
||||
super.onStopNestedScroll(coordinatorLayout, child, target);
|
||||
|
||||
if (mHandler == null)
|
||||
mHandler = new Handler();
|
||||
|
||||
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
child.animate().translationY(0).setInterpolator(new LinearInterpolator()).start();
|
||||
}
|
||||
},1500);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) {
|
||||
super.onNestedScroll(coordinatorLayout, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
|
||||
|
@ -32,6 +49,9 @@ public class FabScrollingBehavior extends CoordinatorLayout.Behavior<FloatingAct
|
|||
|
||||
@Override
|
||||
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionButton child, View directTargetChild, View target, int nestedScrollAxes) {
|
||||
if(mHandler!=null) {
|
||||
mHandler.removeMessages(0);
|
||||
}
|
||||
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL;
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue
Block a user