NestedScrollView
class NestedScrollView : FrameLayout, NestedScrollingParent3, NestedScrollingChild3, ScrollingView
| kotlin.Any | ||||
| ↳ | android.view.View | |||
| ↳ | android.view.ViewGroup | |||
| ↳ | android.widget.FrameLayout | |||
| ↳ | androidx.core.widget.NestedScrollView |
NestedScrollView is just like ScrollView, but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.
Summary
Nested types |
|---|
interface NestedScrollView.OnScrollChangeListenerInterface definition for a callback to be invoked when the scroll X or Y positions of a view change. |
Public constructors |
|---|
NestedScrollView(context: Context) |
NestedScrollView(context: Context, attrs: AttributeSet?) |
NestedScrollView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) |
Public functions |
|
|---|---|
Unit |
|
Unit |
|
Unit |
addView(child: View!, params: ViewGroup.LayoutParams!) |
Unit |
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!) |
Boolean |
arrowScroll(direction: Int)Handle scrolling in response to an up or down arrow click. |
Unit |
|
Boolean |
dispatchKeyEvent(event: KeyEvent!) |
Boolean |
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean) |
Boolean |
dispatchNestedPreFling(velocityX: Float, velocityY: Float) |
Boolean |
dispatchNestedPreScroll( |
Boolean |
dispatchNestedPreScroll(Dispatch one step of a nested scroll in progress before this view consumes any portion of it. |
Boolean |
|
Boolean |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
Unit |
dispatchNestedScroll(Dispatch one step of a nested scroll in progress. |
Unit |
|
Boolean |
executeKeyEvent(event: KeyEvent)You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy. |
Unit |
Fling the scroll view |
Boolean |
fullScroll(direction: Int)Handles scrolling in response to a "home/end" shortcut press. |
Int |
|
Int |
|
Boolean |
|
Boolean |
hasNestedScrollingParent(type: Int)Returns true if this view has a nested scrolling parent for the given input type. |
Boolean |
Indicates whether this ScrollView's content is stretched to fill the viewport. |
Boolean |
|
Boolean |
|
Unit |
|
Boolean |
onGenericMotionEvent(motionEvent: MotionEvent) |
Boolean |
|
Boolean |
onNestedFling( |
Boolean |
onNestedPreFling(target: View, velocityX: Float, velocityY: Float) |
Unit |
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray) |
Unit |
React to a nested scroll in progress before the target view consumes a portion of the scroll. |
Unit |
|
Unit |
onNestedScroll(React to a nested scroll in progress. |
Unit |
onNestedScroll(React to a nested scroll in progress. |
Unit |
onNestedScrollAccepted(child: View, target: View, axes: Int) |
Unit |
onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int)React to the successful claiming of a nested scroll operation. |
Boolean |
onStartNestedScroll(child: View, target: View, axes: Int) |
Boolean |
onStartNestedScroll(child: View, target: View, axes: Int, type: Int)React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate. |
Unit |
onStopNestedScroll(target: View) |
Unit |
onStopNestedScroll(target: View, type: Int)React to a nested scroll operation ending. |
Boolean |
onTouchEvent(motionEvent: MotionEvent) |
Boolean |
pageScroll(direction: Int)Handles scrolling in response to a "page up/down" shortcut press. |
Unit |
requestChildFocus(child: View!, focused: View!) |
Boolean |
requestChildRectangleOnScreen( |
Unit |
requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) |
Unit |
|
Unit |
This version also clamps the scrolling to the bounds of our child. |
Unit |
setFillViewport(fillViewport: Boolean)Set whether this ScrollView should stretch its content height to fill the viewport or not. |
Unit |
setNestedScrollingEnabled(enabled: Boolean) |
Unit |
Register a callback to be invoked when the scroll X or Y positions of this view change. |
Unit |
setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean)Set whether arrow scrolling will animate its transition. |
Boolean |
|
Unit |
smoothScrollBy(dx: Int, dy: Int)Like |
Unit |
smoothScrollBy(dx: Int, dy: Int, scrollDurationMs: Int)Like |
Unit |
smoothScrollTo(x: Int, y: Int)Like |
Unit |
smoothScrollTo(x: Int, y: Int, scrollDurationMs: Int)Like |
Boolean |
startNestedScroll(axes: Int) |
Boolean |
startNestedScroll(axes: Int, type: Int)Begin a nestable scroll operation along the given axes, for the given input type. |
Unit |
|
Unit |
stopNestedScroll(type: Int)Stop a nested scroll in progress for the given input type. |
Protected functions |
|
|---|---|
Int |
Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it). |
Float |
|
Float |
|
Unit |
measureChild( |
Unit |
|
Unit |
|
Unit |
|
Unit |
onOverScrolled( |
Boolean |
onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!)When looking for focus in children of a scroll view, need to be a little more careful not to give focus to something that is scrolled off screen. |
Unit |
onRestoreInstanceState(state: Parcelable!) |
Parcelable |
|
Unit |
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) |
Unit |
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) |
Inherited Constants |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
NestedScrollView
NestedScrollView(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
Public functions
arrowScroll
fun arrowScroll(direction: Int): Boolean
Handle scrolling in response to an up or down arrow click.
| Parameters | |
|---|---|
direction: Int |
The direction corresponding to the arrow key that was pressed |
| Returns | |
|---|---|
Boolean |
True if we consumed the event, false otherwise |
dispatchNestedFling
fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean
dispatchNestedPreScroll
fun dispatchNestedPreScroll(
dx: Int,
dy: Int,
consumed: IntArray?,
offsetInWindow: IntArray?
): Boolean
dispatchNestedPreScroll
fun dispatchNestedPreScroll(
dx: Int,
dy: Int,
consumed: IntArray?,
offsetInWindow: IntArray?,
type: Int
): Boolean
Dispatch one step of a nested scroll in progress before this view consumes any portion of it.
Nested pre-scroll events are to nested scroll events what touch intercept is to touch. dispatchNestedPreScroll offers an opportunity for the parent view in a nested scrolling operation to consume some or all of the scroll operation before the child view consumes it.
| Parameters | |
|---|---|
dx: Int |
Horizontal scroll distance in pixels |
dy: Int |
Vertical scroll distance in pixels |
consumed: IntArray? |
Output. If not null, consumed[0] will contain the consumed component of dx and consumed[1] the consumed dy. |
offsetInWindow: IntArray? |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
type: Int |
the type of input which cause this scroll event |
| Returns | |
|---|---|
Boolean |
true if the parent consumed some or all of the scroll delta |
| See also | |
|---|---|
dispatchNestedScroll |
dispatchNestedScroll
fun dispatchNestedScroll(
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
offsetInWindow: IntArray?
): Boolean
dispatchNestedScroll
fun dispatchNestedScroll(
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
offsetInWindow: IntArray?,
type: Int
): Boolean
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.
| Parameters | |
|---|---|
dxConsumed: Int |
Horizontal distance in pixels consumed by this view during this scroll step |
dyConsumed: Int |
Vertical distance in pixels consumed by this view during this scroll step |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by this view |
dyUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by this view |
offsetInWindow: IntArray? |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
type: Int |
the type of input which cause this scroll event |
| Returns | |
|---|---|
Boolean |
true if the event was dispatched, false if it could not be dispatched. |
| See also | |
|---|---|
dispatchNestedPreScroll |
dispatchNestedScroll
fun dispatchNestedScroll(
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
offsetInWindow: IntArray?,
type: Int,
consumed: IntArray
): Unit
Dispatch one step of a nested scroll in progress.
Implementations of views that support nested scrolling should call this to report info about a scroll in progress to the current nested scrolling parent. If a nested scroll is not currently in progress or nested scrolling is not enabled for this view this method does nothing.
Compatible View implementations should also call dispatchNestedPreScroll before consuming a component of the scroll event themselves.
The original nested scrolling child (where the input events were received to start the scroll) must provide a non-null consumed parameter with values {0, 0}.
| Parameters | |
|---|---|
dxConsumed: Int |
Horizontal distance in pixels consumed by this view during this scroll step |
dyConsumed: Int |
Vertical distance in pixels consumed by this view during this scroll step |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by this view |
dyUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by this view |
offsetInWindow: IntArray? |
Optional. If not null, on return this will contain the offset in local view coordinates of this view from before this operation to after it completes. View implementations may use this to adjust expected input coordinate tracking. |
type: Int |
the type of input which cause this scroll event |
consumed: IntArray |
Output. Upon this method returning, will contain the original values plus any scroll distances consumed by all of this view's nested scrolling parents up the view hierarchy. Index 0 for the x dimension, and index 1 for the y dimension |
| See also | |
|---|---|
onNestedScroll |
executeKeyEvent
fun executeKeyEvent(event: KeyEvent): Boolean
You can call this function yourself to have the scroll view perform scrolling from a key event, just as if the event had been dispatched to it by the view hierarchy.
| Parameters | |
|---|---|
event: KeyEvent |
The key event to execute. |
| Returns | |
|---|---|
Boolean |
Return true if the event was handled, else false. |
fling
fun fling(velocityY: Int): Unit
Fling the scroll view
| Parameters | |
|---|---|
velocityY: Int |
The initial velocity in the Y direction. Positive numbers mean that the finger/cursor is moving down the screen, which means we want to scroll towards the top. |
fullScroll
fun fullScroll(direction: Int): Boolean
Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view to the top or bottom and give the focus to the topmost/bottommost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.
| Parameters | |
|---|---|
direction: Int |
the scroll direction: |
| Returns | |
|---|---|
Boolean |
true if the key event is consumed by this method, false otherwise |
getMaxScrollAmount
fun getMaxScrollAmount(): Int
| Returns | |
|---|---|
Int |
The maximum amount this scroll view will scroll in response to an arrow event. |
hasNestedScrollingParent
fun hasNestedScrollingParent(type: Int): Boolean
Returns true if this view has a nested scrolling parent for the given input type.
The presence of a nested scrolling parent indicates that this view has initiated a nested scroll and it was accepted by an ancestor view further up the view hierarchy.
| Parameters | |
|---|---|
type: Int |
the type of input which cause this scroll event |
| Returns | |
|---|---|
Boolean |
whether this view has a nested scrolling parent |
isFillViewport
fun isFillViewport(): Boolean
Indicates whether this ScrollView's content is stretched to fill the viewport.
name android:fillViewport
| Returns | |
|---|---|
Boolean |
True if the content fills the viewport, false otherwise. |
isSmoothScrollingEnabled
fun isSmoothScrollingEnabled(): Boolean
| Returns | |
|---|---|
Boolean |
Whether arrow scrolling will animate its transition. |
onNestedFling
fun onNestedFling(
target: View,
velocityX: Float,
velocityY: Float,
consumed: Boolean
): Boolean
onNestedPreScroll
fun onNestedPreScroll(
target: View,
dx: Int,
dy: Int,
consumed: IntArray,
type: Int
): Unit
React to a nested scroll in progress before the target view consumes a portion of the scroll.
When working with nested scrolling often the parent view may want an opportunity to consume the scroll before the nested scrolling child does. An example of this is a drawer that contains a scrollable list. The user will want to be able to scroll the list fully into view before the list itself begins scrolling.
onNestedPreScroll is called when a nested scrolling child invokes dispatchNestedPreScroll. The implementation should report how any pixels of the scroll reported by dx, dy were consumed in the consumed array. Index 0 corresponds to dx and index 1 corresponds to dy. This parameter will never be null. Initial values for consumed[0] and consumed[1] will always be 0.
| Parameters | |
|---|---|
target: View |
View that initiated the nested scroll |
dx: Int |
Horizontal scroll distance in pixels |
dy: Int |
Vertical scroll distance in pixels |
consumed: IntArray |
Output. The horizontal and vertical scroll distance consumed by this parent |
type: Int |
the type of input which cause this scroll event |
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int
): Unit
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
type: Int
): Unit
React to a nested scroll in progress.
This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to onStartNestedScroll.
Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
| Parameters | |
|---|---|
target: View |
The descendent view controlling the nested scroll |
dxConsumed: Int |
Horizontal scroll distance in pixels already consumed by target |
dyConsumed: Int |
Vertical scroll distance in pixels already consumed by target |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed: Int |
Vertical scroll distance in pixels not consumed by target |
type: Int |
the type of input which cause this scroll event |
onNestedScroll
fun onNestedScroll(
target: View,
dxConsumed: Int,
dyConsumed: Int,
dxUnconsumed: Int,
dyUnconsumed: Int,
type: Int,
consumed: IntArray
): Unit
React to a nested scroll in progress.
This method will be called when the ViewParent's current nested scrolling child view dispatches a nested scroll event. To receive calls to this method the ViewParent must have previously returned true for a call to onStartNestedScroll.
Both the consumed and unconsumed portions of the scroll distance are reported to the ViewParent. An implementation may choose to use the consumed portion to match or chase scroll position of multiple child elements, for example. The unconsumed portion may be used to allow continuous dragging of multiple scrolling or draggable elements, such as scrolling a list within a vertical drawer where the drawer begins dragging once the edge of inner scrolling content is reached.
This method is called when a nested scrolling child invokes dispatchNestedScroll} or one of methods it overloads.
An implementation must report how many pixels of the the x and y scroll distances were consumed by this nested scrolling parent by adding the consumed distances to the consumed parameter. If this View also implements NestedScrollingChild3, consumed should also be passed up to it's nested scrolling parent so that the parent may also add any scroll distance it consumes. Index 0 corresponds to dx and index 1 corresponds to dy.
| Parameters | |
|---|---|
target: View |
The descendant view controlling the nested scroll |
dxConsumed: Int |
Horizontal scroll distance in pixels already consumed by target |
dyConsumed: Int |
Vertical scroll distance in pixels already consumed by target |
dxUnconsumed: Int |
Horizontal scroll distance in pixels not consumed by target |
dyUnconsumed: Int |
Vertical scroll distance in pixels not consumed by target |
type: Int |
the type of input which cause this scroll event |
consumed: IntArray |
Output. Upon this method returning, will contain the scroll distances consumed by this nested scrolling parent and the scroll distances consumed by any other parent up the view hierarchy |
| See also | |
|---|---|
dispatchNestedScroll |
onNestedScrollAccepted
fun onNestedScrollAccepted(child: View, target: View, axes: Int, type: Int): Unit
React to the successful claiming of a nested scroll operation.
This method will be called after onStartNestedScroll returns true. It offers an opportunity for the view and its superclasses to perform initial configuration for the nested scroll. Implementations of this method should always call their superclass's implementation of this method if one is present.
| Parameters | |
|---|---|
child: View |
Direct child of this ViewParent containing target |
target: View |
View that initiated the nested scroll |
axes: Int |
Flags consisting of |
type: Int |
the type of input which cause this scroll event |
| See also | |
|---|---|
onStartNestedScroll |
|
onStopNestedScroll |
onStartNestedScroll
fun onStartNestedScroll(child: View, target: View, axes: Int, type: Int): Boolean
React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.
This method will be called in response to a descendant view invoking startNestedScroll. Each parent up the view hierarchy will be given an opportunity to respond and claim the nested scrolling operation by returning true.
This method may be overridden by ViewParent implementations to indicate when the view is willing to support a nested scrolling operation that is about to begin. If it returns true, this ViewParent will become the target view's nested scrolling parent for the duration of the scroll operation in progress. When the nested scroll is finished this ViewParent will receive a call to onStopNestedScroll.
| Parameters | |
|---|---|
child: View |
Direct child of this ViewParent containing target |
target: View |
View that initiated the nested scroll |
axes: Int |
Flags consisting of |
type: Int |
the type of input which cause this scroll event |
| Returns | |
|---|---|
Boolean |
true if this ViewParent accepts the nested scroll operation |
onStopNestedScroll
fun onStopNestedScroll(target: View, type: Int): Unit
React to a nested scroll operation ending.
Perform cleanup after a nested scrolling operation. This method will be called when a nested scroll stops, for example when a nested touch scroll ends with a ACTION_UP or ACTION_CANCEL event. Implementations of this method should always call their superclass's implementation of this method if one is present.
pageScroll
fun pageScroll(direction: Int): Boolean
Handles scrolling in response to a "page up/down" shortcut press. This method will scroll the view by one page up or down and give the focus to the topmost/bottommost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.
| Parameters | |
|---|---|
direction: Int |
the scroll direction: |
| Returns | |
|---|---|
Boolean |
true if the key event is consumed by this method, false otherwise |
requestChildRectangleOnScreen
fun requestChildRectangleOnScreen(
child: View,
rectangle: Rect!,
immediate: Boolean
): Boolean
requestDisallowInterceptTouchEvent
fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit
scrollTo
fun scrollTo(x: Int, y: Int): Unit
This version also clamps the scrolling to the bounds of our child.
setFillViewport
fun setFillViewport(fillViewport: Boolean): Unit
Set whether this ScrollView should stretch its content height to fill the viewport or not.
name android:fillViewport
| Parameters | |
|---|---|
fillViewport: Boolean |
True to stretch the content's height to the viewport's boundaries, false otherwise. |
setOnScrollChangeListener
fun setOnScrollChangeListener(l: NestedScrollView.OnScrollChangeListener?): Unit
Register a callback to be invoked when the scroll X or Y positions of this view change.
This version of the method works on all versions of Android, back to API v4.
| Parameters | |
|---|---|
l: NestedScrollView.OnScrollChangeListener? |
The listener to notify when the scroll X or Y position changes. |
| See also | |
|---|---|
getScrollX |
|
getScrollY |
setSmoothScrollingEnabled
fun setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean): Unit
Set whether arrow scrolling will animate its transition.
| Parameters | |
|---|---|
smoothScrollingEnabled: Boolean |
whether arrow scrolling will animate its transition |
smoothScrollBy
fun smoothScrollBy(dx: Int, dy: Int): Unit
Like scrollBy, but scroll smoothly instead of immediately.
smoothScrollBy
fun smoothScrollBy(dx: Int, dy: Int, scrollDurationMs: Int): Unit
Like scrollBy, but scroll smoothly instead of immediately.
smoothScrollTo
fun smoothScrollTo(x: Int, y: Int): Unit
Like scrollTo, but scroll smoothly instead of immediately.
smoothScrollTo
fun smoothScrollTo(x: Int, y: Int, scrollDurationMs: Int): Unit
Like scrollTo, but scroll smoothly instead of immediately.
startNestedScroll
fun startNestedScroll(axes: Int, type: Int): Boolean
Begin a nestable scroll operation along the given axes, for the given input type.
A view starting a nested scroll promises to abide by the following contract:
The view will call startNestedScroll upon initiating a scroll operation. In the case of a touch scroll type this corresponds to the initial ACTION_DOWN. In the case of touch scrolling the nested scroll will be terminated automatically in the same manner as requestDisallowInterceptTouchEvent. In the event of programmatic scrolling the caller must explicitly call stopNestedScroll to indicate the end of the nested scroll.
If startNestedScroll returns true, a cooperative parent was found. If it returns false the caller may ignore the rest of this contract until the next scroll. Calling startNestedScroll while a nested scroll is already in progress will return true.
At each incremental step of the scroll the caller should invoke dispatchNestedPreScroll once it has calculated the requested scrolling delta. If it returns true the nested scrolling parent at least partially consumed the scroll and the caller should adjust the amount it scrolls by.
After applying the remainder of the scroll delta the caller should invoke dispatchNestedScroll, passing both the delta consumed and the delta unconsumed. A nested scrolling parent may treat these values differently. See onNestedScroll.
| Parameters | |
|---|---|
axes: Int |
Flags consisting of a combination of |
type: Int |
the type of input which cause this scroll event |
| Returns | |
|---|---|
Boolean |
true if a cooperative parent was found and nested scrolling has been enabled for the current gesture. |
stopNestedScroll
fun stopNestedScroll(type: Int): Unit
Stop a nested scroll in progress for the given input type.
Calling this method when a nested scroll is not currently in progress is harmless.
| Parameters | |
|---|---|
type: Int |
the type of input which cause this scroll event |
| See also | |
|---|---|
startNestedScroll |
Protected functions
computeScrollDeltaToGetChildRectOnScreen
protected fun computeScrollDeltaToGetChildRectOnScreen(rect: Rect!): Int
Compute the amount to scroll in the Y direction in order to get a rectangle completely on the screen (or, if taller than the screen, at least the first screen size chunk of it).
| Parameters | |
|---|---|
rect: Rect! |
The rect. |
| Returns | |
|---|---|
Int |
The scroll delta. |
measureChild
protected fun measureChild(
child: View,
parentWidthMeasureSpec: Int,
parentHeightMeasureSpec: Int
): Unit
measureChildWithMargins
protected fun measureChildWithMargins(
child: View!,
parentWidthMeasureSpec: Int,
widthUsed: Int,
parentHeightMeasureSpec: Int,
heightUsed: Int
): Unit
onOverScrolled
protected fun onOverScrolled(
scrollX: Int,
scrollY: Int,
clampedX: Boolean,
clampedY: Boolean
): Unit
onRequestFocusInDescendants
protected fun onRequestFocusInDescendants(direction: Int, previouslyFocusedRect: Rect!): Boolean
When looking for focus in children of a scroll view, need to be a little more careful not to give focus to something that is scrolled off screen. This is more expensive than the default ViewGroup implementation, otherwise this behavior might have been made the default.