NestedScrollView

open 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 android.widget.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 classes
abstract

Interface definition for a callback to be invoked when the scroll X or Y positions of a view change.

Public constructors
<init>(@NonNull context: Context)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

Public methods
open Unit
addView(child: View!)

open Unit
addView(child: View!, index: Int)

open Unit
addView(child: View!, params: LayoutParams!)

open Unit
addView(child: View!, index: Int, params: LayoutParams!)

open Unit

open Boolean
pageScroll(direction: Int)

Handles scrolling in response to a "page up/down" shortcut press.

open Boolean

open Int

open Boolean
onNestedFling(target: View, velocityX: Float, velocityY: Float, consumed: Boolean)

open Unit
requestChildFocus(child: View!, focused: View!)

open Boolean
arrowScroll(direction: Int)

Handle scrolling in response to an up or down arrow click.

open Boolean

open Unit

Register a callback to be invoked when the scroll X or Y positions of this view change.

open Unit
onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int)

open Unit
onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray)

open Unit
onStopNestedScroll(@NonNull target: View, type: Int)

open Unit

open Unit

open Unit
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, @Nullable offsetInWindow: IntArray?, type: Int, @NonNull consumed: IntArray)

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?, type: Int)

open Boolean
dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?)

open Boolean
dispatchNestedPreFling(velocityX: Float, velocityY: Float)

open Boolean
startNestedScroll(axes: Int, type: Int)

open Boolean

open Boolean
requestChildRectangleOnScreen(child: View!, rectangle: Rect!, immediate: Boolean)

Unit
smoothScrollBy(dx: Int, dy: Int)

Like View#scrollBy, but scroll smoothly instead of immediately.

open Boolean

open Boolean
onStartNestedScroll(@NonNull child: View, @NonNull target: View, axes: Int, type: Int)

open Boolean
onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int)

open Unit
fling(velocityY: Int)

Fling the scroll view

open Int

open Unit

open Unit
scrollTo(x: Int, y: Int)

This version also clamps the scrolling to the bounds of our child.

open Unit
onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, axes: Int, type: Int)

open Unit
onNestedScrollAccepted(child: View, target: View, nestedScrollAxes: Int)

open Unit

open Unit
draw(canvas: Canvas!)

open Boolean

open Unit
setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean)

Set whether arrow scrolling will animate its transition.

open Boolean
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean)

open Unit
setFillViewport(fillViewport: Boolean)

Set whether this ScrollView should stretch its content height to fill the viewport or not.

open Boolean

open Unit

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?, type: Int)

open Boolean
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?)

open Unit
onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, @NonNull consumed: IntArray)

open Unit
onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int)

open Unit
onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int)

open Unit

open Unit

open Boolean

Unit

Like scrollTo, but scroll smoothly instead of immediately.

open Boolean
executeKeyEvent(@NonNull 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.

open Boolean
onNestedPreFling(target: View, velocityX: Float, velocityY: Float)

open Boolean

open Boolean

Indicates whether this ScrollView's content is stretched to fill the viewport.

open Boolean

open Boolean

open Boolean
fullScroll(direction: Int)

Handles scrolling in response to a "home/end" shortcut press.

Protected methods
open 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).

open Unit
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int)

open Parcelable!

open 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.

open Unit
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int)

open Unit
onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int)

open Unit
measureChild(child: View!, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int)

open Unit
onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean)

open Float

open Unit
measureChildWithMargins(child: View!, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int)

open Float

open Unit
onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int)

open Unit

Public constructors

<init>

NestedScrollView(@NonNull context: Context)

<init>

NestedScrollView(@NonNull context: Context, @Nullable attrs: AttributeSet?)

<init>

NestedScrollView(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int)

Public methods

addView

open fun addView(child: View!): Unit

addView

open fun addView(child: View!, index: Int): Unit

addView

open fun addView(child: View!, params: LayoutParams!): Unit

addView

open fun addView(child: View!, index: Int, params: LayoutParams!): Unit

onAttachedToWindow

open fun onAttachedToWindow(): Unit

pageScroll

open 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: android.view.View#FOCUS_UP to go one page up or android.view.View#FOCUS_DOWN to go one page down
Return
Boolean: true if the key event is consumed by this method, false otherwise

onTouchEvent

open fun onTouchEvent(ev: MotionEvent!): Boolean

getNestedScrollAxes

open fun getNestedScrollAxes(): Int

onNestedFling

open fun onNestedFling(target: View, velocityX: Float, velocityY: Float, consumed: Boolean): Boolean

requestChildFocus

open fun requestChildFocus(child: View!, focused: View!): Unit

arrowScroll

open 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
Return
Boolean: True if we consumed the event, false otherwise

isSmoothScrollingEnabled

open fun isSmoothScrollingEnabled(): Boolean
Return
Boolean: Whether arrow scrolling will animate its transition.

setOnScrollChangeListener

open fun setOnScrollChangeListener(@Nullable 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.

onNestedPreScroll

open fun onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int): Unit

onNestedPreScroll

open fun onNestedPreScroll(target: View, dx: Int, dy: Int, consumed: IntArray): Unit

onStopNestedScroll

open fun onStopNestedScroll(@NonNull target: View, type: Int): Unit

onStopNestedScroll

open fun onStopNestedScroll(target: View): Unit

setNestedScrollingEnabled

open fun setNestedScrollingEnabled(enabled: Boolean): Unit

dispatchNestedScroll

open fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, @Nullable offsetInWindow: IntArray?, type: Int, @NonNull consumed: IntArray): Unit

dispatchNestedScroll

open fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?, type: Int): Boolean

dispatchNestedScroll

open fun dispatchNestedScroll(dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, offsetInWindow: IntArray?): Boolean

dispatchNestedPreFling

open fun dispatchNestedPreFling(velocityX: Float, velocityY: Float): Boolean

startNestedScroll

open fun startNestedScroll(axes: Int, type: Int): Boolean

startNestedScroll

open fun startNestedScroll(axes: Int): Boolean

requestChildRectangleOnScreen

open fun requestChildRectangleOnScreen(child: View!, rectangle: Rect!, immediate: Boolean): Boolean

smoothScrollBy

fun smoothScrollBy(dx: Int, dy: Int): Unit

Like View#scrollBy, but scroll smoothly instead of immediately.

Parameters
dx Int: the number of pixels to scroll by on the X axis
dy Int: the number of pixels to scroll by on the Y axis

dispatchKeyEvent

open fun dispatchKeyEvent(event: KeyEvent!): Boolean

onStartNestedScroll

open fun onStartNestedScroll(@NonNull child: View, @NonNull target: View, axes: Int, type: Int): Boolean

onStartNestedScroll

open fun onStartNestedScroll(child: View, target: View, nestedScrollAxes: Int): Boolean

fling

open 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.

getMaxScrollAmount

open fun getMaxScrollAmount(): Int
Return
Int: The maximum amount this scroll view will scroll in response to an arrow event.

computeScroll

open fun computeScroll(): Unit

scrollTo

open fun scrollTo(x: Int, y: Int): Unit

This version also clamps the scrolling to the bounds of our child.

onNestedScrollAccepted

open fun onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, axes: Int, type: Int): Unit

onNestedScrollAccepted

open fun onNestedScrollAccepted(child: View, target: View, nestedScrollAxes: Int): Unit

requestLayout

open fun requestLayout(): Unit

draw

open fun draw(canvas: Canvas!): Unit

shouldDelayChildPressedState

open fun shouldDelayChildPressedState(): Boolean

setSmoothScrollingEnabled

open fun setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean): Unit

Set whether arrow scrolling will animate its transition.

Parameters
smoothScrollingEnabled Boolean: whether arrow scrolling will animate its transition

dispatchNestedFling

open fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean

setFillViewport

open fun setFillViewport(fillViewport: Boolean): Unit

Set whether this ScrollView should stretch its content height to fill the viewport or not.

Parameters
fillViewport Boolean: True to stretch the content's height to the viewport's boundaries, false otherwise.

isNestedScrollingEnabled

open fun isNestedScrollingEnabled(): Boolean

requestDisallowInterceptTouchEvent

open fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?, type: Int): Boolean

dispatchNestedPreScroll

open fun dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?): Boolean

onNestedScroll

open fun onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int, @NonNull consumed: IntArray): Unit

onNestedScroll

open fun onNestedScroll(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int, type: Int): Unit

onNestedScroll

open fun onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int): Unit

stopNestedScroll

open fun stopNestedScroll(type: Int): Unit

stopNestedScroll

open fun stopNestedScroll(): Unit

onGenericMotionEvent

open fun onGenericMotionEvent(event: MotionEvent!): Boolean

smoothScrollTo

fun smoothScrollTo(x: Int, y: Int): Unit

Like scrollTo, but scroll smoothly instead of immediately.

Parameters
x Int: the position where to scroll on the X axis
y Int: the position where to scroll on the Y axis

executeKeyEvent

open fun executeKeyEvent(@NonNull 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.
Return
Boolean: Return true if the event was handled, else false.

onNestedPreFling

open fun onNestedPreFling(target: View, velocityX: Float, velocityY: Float): Boolean

onInterceptTouchEvent

open fun onInterceptTouchEvent(ev: MotionEvent!): Boolean

isFillViewport

open fun isFillViewport(): Boolean

Indicates whether this ScrollView's content is stretched to fill the viewport.

Return
Boolean: True if the content fills the viewport, false otherwise.

hasNestedScrollingParent

open fun hasNestedScrollingParent(type: Int): Boolean

hasNestedScrollingParent

open fun hasNestedScrollingParent(): Boolean

fullScroll

open 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: android.view.View#FOCUS_UP to go the top of the view or android.view.View#FOCUS_DOWN to go the bottom
Return
Boolean: true if the key event is consumed by this method, false otherwise

Protected methods

computeScrollDeltaToGetChildRectOnScreen

protected open 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.
Return
Int: The scroll delta.

onSizeChanged

protected open fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

onRequestFocusInDescendants

protected open 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 android.view.ViewGroup implementation, otherwise this behavior might have been made the default.

onScrollChanged

protected open fun onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int): Unit

onLayout

protected open fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int): Unit

measureChild

protected open fun measureChild(child: View!, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int): Unit

onOverScrolled

protected open fun onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean): Unit

getTopFadingEdgeStrength

protected open fun getTopFadingEdgeStrength(): Float

measureChildWithMargins

protected open fun measureChildWithMargins(child: View!, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int): Unit

getBottomFadingEdgeStrength

protected open fun getBottomFadingEdgeStrength(): Float

onMeasure

protected open fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int): Unit

onRestoreInstanceState

protected open fun onRestoreInstanceState(state: Parcelable!): Unit