Added in API level 1

ScrollView


open class ScrollView : FrameLayout
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.FrameLayout
   ↳ android.widget.ScrollView

A view group that allows the view hierarchy placed within it to be scrolled. Scroll view may have only one direct child placed within it. To add multiple views within the scroll view, make the direct child you add a view group, for example LinearLayout, and place additional views within that LinearLayout.

Scroll view supports vertical scrolling only. For horizontal scrolling, use HorizontalScrollView instead.

Never add a androidx.recyclerview.widget.RecyclerView or ListView to a scroll view. Doing so results in poor user interface performance and a poor user experience.

For vertical scrolling, consider androidx.core.widget.NestedScrollView instead of scroll view which offers greater user interface flexibility and support for the material design scrolling patterns.

Material Design offers guidelines on how the appearance of several UI components, including app bars and banners, should respond to gestures.

Summary

XML attributes
android:fillViewport Defines whether the scrollview should stretch its content to fill the viewport.
Inherited XML attributes
Inherited constants
Public constructors
ScrollView(context: Context!)

ScrollView(context: Context!, attrs: AttributeSet!)

ScrollView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

ScrollView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit
addView(child: View!)

Adds a child view.

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

Adds a child view with the specified layout parameters.

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

Adds a child view.

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

Adds a child view with the specified layout parameters.

open Boolean
arrowScroll(direction: Int)

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

open Unit

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.

open Boolean

Dispatch a key event to the next view on the focus path.

open Unit
draw(canvas: Canvas)

Manually render this view (and all of its children) to the given Canvas.

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

open Unit
fling(velocityY: Int)

Fling the scroll view

open Boolean
fullScroll(direction: Int)

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

open CharSequence!

Return the class name of this object to be used for accessibility purposes.

open Int

Returns the bottom edge effect color.

open Int

open Int

Returns the top edge effect color.

open Boolean

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

open Boolean

open Boolean

Implement this method to handle generic motion events.

open Boolean

Implement this method to intercept all touch screen motion events.

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

Request a fling from a nested scroll.

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

React to a nested scroll in progress.

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

React to the successful claiming of a nested scroll operation.

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

React to a descendant view initiating a nestable scroll operation, claiming the nested scroll operation if appropriate.

open Unit

React to a nested scroll operation ending.

open Boolean

Implement this method to handle pointer events.

open Boolean
pageScroll(direction: Int)

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

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

Called when a child of this parent wants focus

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

Called when a child of this group wants a particular rectangle to be positioned onto the screen.

open Unit

Called when a child does not want this parent and its ancestors to intercept touch events with ViewGroup.onInterceptTouchEvent(MotionEvent).

open Unit

Call this when something has changed which has invalidated the layout of this view.

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

Set the scrolled position of your view.

open Unit

Scrolls the view to the given child.

open Unit

Sets the bottom edge effect color.

open Unit

Sets the edge effect color for both top and bottom edge effects.

open Unit
setFillViewport(fillViewport: Boolean)

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

open Unit
setSmoothScrollingEnabled(smoothScrollingEnabled: Boolean)

Set whether arrow scrolling will animate its transition.

open Unit

Sets the top edge effect color.

open Boolean

Return true if the pressed state should be delayed for children or descendants of this ViewGroup.

Unit
smoothScrollBy(dx: Int, dy: Int)

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

Unit

Like scrollTo, but scroll smoothly instead of immediately.

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 Int

Compute the vertical offset of the vertical scrollbar's thumb within the horizontal range.

open Int

The scroll range of a scroll view is the overall height of all of its children.

open Float

Returns the strength, or intensity, of the bottom faded edge.

open Float

Returns the strength, or intensity, of the top faded edge.

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

Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding.

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

Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding and margins.

open Unit

This is called when the view is detached from a window.

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

Called from layout when this view should assign a size and position to each of its children.

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

Measure the view and its content to determine the measured width and the measured height.

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

Called by overScrollBy(int,int,int,int,int,int,int,int,boolean) to respond to the results of an over-scroll operation.

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

Hook allowing a view to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState.

open Parcelable?

Hook allowing a view to generate a representation of its internal state that can later be used to create a new instance with that same state.

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

This is called during layout when the size of this view has changed.

Inherited functions