public interface OnScrollListener
To make the api more close to human visual instinct, the offset used in the callback method of this interface is transformed. As we are scrolling vertically, we only care about offset in the vertical axis, i.e. axis y.
For header view we use the bottom of the view along the axis y as the coordinate. for content view we use the top the the view along axis y as the coordinate, their coordinate system is the same, and the same as the parent view's original touch event coordinate system.
o---------------------------------> x
| |
| |
| |
| |
| |
| CoordinatorLayout |
| |
| |
| |
| |
| |
|footer_o |
|-----------------------
|
|
|
v
y (header_bottom_y, content_top_y)
header_offset = header_bottom_y
content_offset = content_top_y
Fot the footer view we use the top of the view along the axis y as the coordinate to compute offset, it's coordinate system's original point is at the left-bottom corner of parent view, as show in the figure below.
y (footer_top_y)
^
|
|
|-----------------------
| |
| |
| |
| |
| |
| CoordinatorLayout |
| |
| |
| |
| |
| |
| |
o---------------------------------> x
footer_offset = footer_top_y
| Modifier and Type | Method and Description |
|---|---|
void |
onScroll(CoordinatorLayout parent,
android.view.View view,
int current,
int delta,
int initial,
int trigger,
int min,
int max,
int type)
The view that a behavior is attached is scrolling now, you can care less about which type of
touch event type now, because no matter what the touch event is, it just scrolls.
|
void |
onStartScroll(CoordinatorLayout parent,
android.view.View view,
int initial,
int trigger,
int min,
int max,
int type)
The view that a behavior is attached is starting to scroll, when implementing this method,
you should be careful with which type of touch event causes the scroll to happen.
|
void |
onStopScroll(CoordinatorLayout parent,
android.view.View view,
int current,
int initial,
int trigger,
int min,
int max,
int type)
The view that a behavior is attached has stopped to scroll, when implementing this method,
you should be careful with which type of touch event causes the scrolling.
|
void onStartScroll(CoordinatorLayout parent,
android.view.View view,
int initial,
int trigger,
int min,
int max,
int type)
onStopScroll(CoordinatorLayout, View, int, int, int, int, int, int) method of
this interface.
The reason is that after a normal touch scroll is end, it may be followed by a fling motion immediately which can cause this method be invoked again and start another start-scroll-stop round.
parent - the view's parent view, it must be CoordinatorLayoutview - the view to which the behavior is attachedinitial - the initial offset of the viewtrigger - the trigger offset of the view related to the refreshing state changingmin - the minimum offset of the view, the view can not scroll out of the range
limited by minimum and maximum offsetmax - the maximum offset of the view the view can not scroll out of the range
limited by minimum and maximum offsettype - the type of touch event that cause the scrolling to happenvoid onScroll(CoordinatorLayout parent,
android.view.View view,
int current,
int delta,
int initial,
int trigger,
int min,
int max,
int type)
Note: When compute a progress percentage, because all the number values are integers, you may need to do some number type conversion to make things right.
parent - the view's parent view, it must be CoordinatorLayoutview - the view to which the behavior is attachedcurrent - the current offset of the viewdelta - the offset deltainitial - the initial offset of the viewtrigger - the trigger offset of the view related to the refreshing state changingmin - the minimum offset of the view, the view can not scroll out of the range
limited by minimum and maximum offsetmax - the maximum offset of the view the view can not scroll out of the range
limited by minimum and maximum offsettype - the type of touch event that cause the scrolling to happenvoid onStopScroll(CoordinatorLayout parent,
android.view.View view,
int current,
int initial,
int trigger,
int min,
int max,
int type)
The reason is the same as the onStartScroll(CoordinatorLayout, View, int, int,
int, int, int) method.
parent - the view's parent view, it must be CoordinatorLayoutview - the view to which the behavior is attachedcurrent - the current offset of the viewinitial - the initial offset of the viewtrigger - the trigger offset of the view related to the refreshing state changingmin - the minimum offset of the view, the view can not scroll out of the range
limited by minimum and maximum offsetmax - the maximum offset of the view the view can not scroll out of the range
limited by minimum and maximum offsettype - the type of touch event that cause the scrolling to happenonStartScroll(CoordinatorLayout, View, int, int, int, int, int)