-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
iMeiji
committed
Jul 27, 2017
1 parent
3ed8529
commit a00aa72
Showing
9 changed files
with
238 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
app/src/main/java/com/meiji/toutiao/widget/behavior/ScrollAwareFABBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.meiji.toutiao.widget.behavior; | ||
|
||
import android.content.Context; | ||
import android.support.design.widget.CoordinatorLayout; | ||
import android.support.design.widget.FloatingActionButton; | ||
import android.support.v4.view.ViewCompat; | ||
import android.util.AttributeSet; | ||
import android.view.View; | ||
|
||
/** | ||
* Created by Meiji on 2017/7/28. | ||
* FAB 上滑隐藏 下滑显示 | ||
*/ | ||
|
||
public class ScrollAwareFABBehavior extends FloatingActionButton.Behavior { | ||
|
||
public ScrollAwareFABBehavior(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, | ||
FloatingActionButton child, | ||
View directTargetChild, | ||
View target, | ||
int nestedScrollAxes) { | ||
return nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL || | ||
super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target, nestedScrollAxes); | ||
} | ||
|
||
@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); | ||
|
||
if (dyConsumed > 0 && child.getVisibility() == View.VISIBLE) { | ||
child.setVisibility(View.INVISIBLE); | ||
} else if (dyConsumed < 0 && child.getVisibility() != View.VISIBLE) { | ||
child.show(); | ||
} | ||
} | ||
} |
Oops, something went wrong.