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, @Nullable attrs: AttributeSet?) |
|
<init>(@NonNull context: Context, @Nullable attrs: AttributeSet?, defStyleAttr: Int) |
Public methods |
|
---|---|
open Unit | |
open Unit | |
open Unit |
addView(child: View!, params: LayoutParams!) |
open Unit |
addView(child: View!, index: Int, params: LayoutParams!) |
open Boolean |
arrowScroll(direction: Int) Handle scrolling in response to an up or down arrow click. |
open Unit | |
open Boolean |
dispatchKeyEvent(event: KeyEvent!) |
open Boolean |
dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean) |
open Boolean |
dispatchNestedPreFling(velocityX: Float, velocityY: Float) |
open Boolean | |
open Boolean |
dispatchNestedPreScroll(dx: Int, dy: Int, consumed: IntArray?, offsetInWindow: IntArray?) |
open Unit | |
open Boolean | |
open Boolean | |
open Unit | |
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 Unit |
Fling the scroll view |
open Boolean |
fullScroll(direction: Int) Handles scrolling in response to a "home/end" shortcut press. |
open Int | |
open Int | |
open Boolean |
hasNestedScrollingParent(type: Int) |
open Boolean | |
open Boolean |
Indicates whether this ScrollView's content is stretched to fill the viewport. |
open Boolean | |
open Boolean | |
open Unit | |
open Boolean |
onGenericMotionEvent(event: MotionEvent!) |
open Boolean | |
open Boolean |
onNestedFling(@NonNull target: View, velocityX: Float, velocityY: Float, consumed: Boolean) |
open Boolean |
onNestedPreFling(@NonNull target: View, velocityX: Float, velocityY: Float) |
open Unit | |
open Unit |
onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray) |
open Unit | |
open Unit | |
open Unit | |
open Unit |
onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, axes: Int, type: Int) |
open Unit |
onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, nestedScrollAxes: Int) |
open Boolean |
onStartNestedScroll(@NonNull child: View, @NonNull target: View, axes: Int, type: Int) |
open Boolean |
onStartNestedScroll(@NonNull child: View, @NonNull target: View, nestedScrollAxes: Int) |
open Unit |
onStopNestedScroll(@NonNull target: View, type: Int) |
open Unit |
onStopNestedScroll(@NonNull target: View) |
open Boolean |
onTouchEvent(ev: MotionEvent!) |
open Boolean |
pageScroll(direction: Int) Handles scrolling in response to a "page up/down" shortcut press. |
open Unit |
requestChildFocus(child: View!, focused: View!) |
open Boolean |
requestChildRectangleOnScreen(child: View!, rectangle: Rect!, immediate: Boolean) |
open Unit |
requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) |
open Unit | |
open Unit |
This version also clamps the scrolling to the bounds of our child. |
open Unit |
setFillViewport(fillViewport: Boolean) Set whether this ScrollView should stretch its content height to fill the viewport or not. |
open Unit |
setNestedScrollingEnabled(enabled: Boolean) |
open Unit |
setOnScrollChangeListener(@Nullable l: NestedScrollView.OnScrollChangeListener?) Register a callback to be invoked when the scroll X or Y positions of this view change. |
open Unit |
setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean) Set whether arrow scrolling will animate its transition. |
open Boolean | |
Unit |
smoothScrollBy(dx: Int, dy: Int) Like |
Unit |
smoothScrollTo(x: Int, y: Int) Like |
open Boolean |
startNestedScroll(axes: Int, type: Int) |
open Boolean |
startNestedScroll(axes: Int) |
open Unit |
stopNestedScroll(type: Int) |
open Unit |
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 Float | |
open Float | |
open Unit |
measureChild(child: View!, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int) |
open Unit | |
open Unit | |
open Unit | |
open Unit |
onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean) |
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 |
onRestoreInstanceState(state: Parcelable!) |
open Parcelable! | |
open Unit |
onScrollChanged(l: Int, t: Int, oldl: Int, oldt: Int) |
open Unit |
onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) |
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!, params: LayoutParams!): Unit
addView
open fun addView(child: View!, index: Int, params: LayoutParams!): 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 |
computeScroll
open fun computeScroll(): Unit
dispatchNestedFling
open fun dispatchNestedFling(velocityX: Float, velocityY: Float, consumed: Boolean): Boolean
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
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
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. |
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. |
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 |
getMaxScrollAmount
open fun getMaxScrollAmount(): Int
Return | |
---|---|
Int: The maximum amount this scroll view will scroll in response to an arrow event. |
getNestedScrollAxes
open fun getNestedScrollAxes(): Int
hasNestedScrollingParent
open fun hasNestedScrollingParent(): 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. |
isNestedScrollingEnabled
open fun isNestedScrollingEnabled(): Boolean
isSmoothScrollingEnabled
open fun isSmoothScrollingEnabled(): Boolean
Return | |
---|---|
Boolean: Whether arrow scrolling will animate its transition. |
onAttachedToWindow
open fun onAttachedToWindow(): Unit
onGenericMotionEvent
open fun onGenericMotionEvent(event: MotionEvent!): Boolean
onInterceptTouchEvent
open fun onInterceptTouchEvent(ev: MotionEvent!): Boolean
onNestedFling
open fun onNestedFling(@NonNull target: View, velocityX: Float, velocityY: Float, consumed: Boolean): Boolean
onNestedPreFling
open fun onNestedPreFling(@NonNull target: View, velocityX: Float, velocityY: Float): Boolean
onNestedPreScroll
open fun onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray, type: Int): Unit
onNestedPreScroll
open fun onNestedPreScroll(@NonNull target: View, dx: Int, dy: Int, @NonNull consumed: IntArray): Unit
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(@NonNull target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int): Unit
onNestedScrollAccepted
open fun onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, axes: Int, type: Int): Unit
onNestedScrollAccepted
open fun onNestedScrollAccepted(@NonNull child: View, @NonNull target: View, nestedScrollAxes: Int): Unit
onStartNestedScroll
open fun onStartNestedScroll(@NonNull child: View, @NonNull target: View, axes: Int, type: Int): Boolean
onStartNestedScroll
open fun onStartNestedScroll(@NonNull child: View, @NonNull target: View, nestedScrollAxes: Int): Boolean
onTouchEvent
open fun onTouchEvent(ev: MotionEvent!): Boolean
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 |
requestChildRectangleOnScreen
open fun requestChildRectangleOnScreen(child: View!, rectangle: Rect!, immediate: Boolean): Boolean
requestDisallowInterceptTouchEvent
open fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean): Unit
requestLayout
open fun requestLayout(): Unit
scrollTo
open fun scrollTo(x: Int, y: Int): Unit
This version also clamps the scrolling to the bounds of our child.
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. |
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. |
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 |
shouldDelayChildPressedState
open fun shouldDelayChildPressedState(): 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 |
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 |
stopNestedScroll
open fun stopNestedScroll(): Unit
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. |
getBottomFadingEdgeStrength
protected open fun getBottomFadingEdgeStrength(): Float
getTopFadingEdgeStrength
protected open fun getTopFadingEdgeStrength(): Float
measureChild
protected open fun measureChild(child: View!, parentWidthMeasureSpec: Int, parentHeightMeasureSpec: Int): Unit
measureChildWithMargins
protected open fun measureChildWithMargins(child: View!, parentWidthMeasureSpec: Int, widthUsed: Int, parentHeightMeasureSpec: Int, heightUsed: Int): Unit
onOverScrolled
protected open fun onOverScrolled(scrollX: Int, scrollY: Int, clampedX: Boolean, clampedY: Boolean): Unit
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.
onRestoreInstanceState
protected open fun onRestoreInstanceState(state: Parcelable!): Unit
onSaveInstanceState
protected open fun onSaveInstanceState(): Parcelable!