java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.FrameLayout | |||
↳ | android.widget.HorizontalScrollView |
Layout container for a view hierarchy that can be scrolled by the user, allowing it to be larger than the physical display. A HorizontalScrollView is a FrameLayout, meaning you should place one child in it containing the entire contents to scroll; this child may itself be a layout manager with a complex hierarchy of objects. A child that is often used is a LinearLayout in a horizontal orientation, presenting a horizontal array of top-level items that the user can scroll through.
You should never use a HorizontalScrollView with a ListView, since ListView takes care of its own scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by HorizontalScrollView.
The TextView class also takes care of its own scrolling, so does not require a ScrollView, but using the two together is possible to achieve the effect of a text view within a larger container.
HorizontalScrollView only supports horizontal scrolling.
[Expand]
Inherited XML Attributes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.widget.FrameLayout
| |||||||||||
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.view.ViewGroup
| |||||||||||
From class
android.view.View
|
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Adds a child view.
| |||||||||||
Adds a child view with the specified layout parameters.
| |||||||||||
Adds a child view with the specified layout parameters.
| |||||||||||
Adds a child view.
| |||||||||||
Handle scrolling in response to a left or right arrow click.
| |||||||||||
Called by a parent to request that a child update its values for mScrollX
and mScrollY if necessary.
| |||||||||||
Dispatch a key event to the next view on the focus path.
| |||||||||||
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.
| |||||||||||
Fling the scroll view
| |||||||||||
Handles scrolling in response to a "home/end" shortcut press. | |||||||||||
Indicates whether this ScrollView's content is stretched to fill the viewport.
| |||||||||||
Implement this method to intercept all touch screen motion events.
| |||||||||||
Implement this method to handle touch screen motion events.
| |||||||||||
Handles scrolling in response to a "page up/down" shortcut press. | |||||||||||
Called when a child of this parent wants focus
| |||||||||||
Called when a child of this group wants a particular rectangle to be
positioned onto the screen.
| |||||||||||
Call this when something has changed which has invalidated the
layout of this view.
| |||||||||||
Set the scrolled position of your view.
This version also clamps the scrolling to the bounds of our child. | |||||||||||
Indicates this ScrollView whether it should stretch its content width to fill
the viewport or not.
| |||||||||||
Set whether arrow scrolling will animate its transition.
| |||||||||||
Like scrollBy(int, int), but scroll smoothly instead of immediately.
| |||||||||||
Like scrollTo(int, int), but scroll smoothly instead of immediately.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
The scroll range of a scroll view is the overall width of all of its children. | |||||||||||
Compute the amount to scroll in the X 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).
| |||||||||||
Returns the strength, or intensity, of the left faded edge.
| |||||||||||
Returns the strength, or intensity, of the right faded edge.
| |||||||||||
Ask one of the children of this view to measure itself, taking into
account both the MeasureSpec requirements for this view and its padding.
| |||||||||||
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.
| |||||||||||
Called from layout when this view should
assign a size and position to each of its children.
| |||||||||||
Measure the view and its content to determine the measured width and the measured height. | |||||||||||
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 called during layout when the size of this view has changed.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class android.widget.FrameLayout
| |||||||||||
From class android.view.ViewGroup
| |||||||||||
From class android.view.View
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface android.graphics.drawable.Drawable.Callback
| |||||||||||
From interface android.view.KeyEvent.Callback
| |||||||||||
From interface android.view.ViewManager
| |||||||||||
From interface android.view.ViewParent
|
Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.
child | the child view to add |
---|---|
index | the position at which to add the child |
Adds a child view with the specified layout parameters.
child | the child view to add |
---|---|
params | the layout parameters to set on the child |
Adds a child view with the specified layout parameters.
child | the child view to add |
---|---|
index | the position at which to add the child |
params | the layout parameters to set on the child |
Adds a child view. If no layout parameters are already set on the child, the default parameters for this ViewGroup are set on the child.
child | the child view to add |
---|
Handle scrolling in response to a left or right arrow click.
direction | The direction corresponding to the arrow key that was pressed |
---|
Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary. This will typically be done if the child is animating a scroll using a Scroller object.
Dispatch a key event to the next view on the focus path. This path runs from the top of the view tree down to the currently focused view. If this view has focus, it will dispatch to itself. Otherwise it will dispatch the next node down the focus path. This method also fires any key listeners.
event | The key event to be dispatched. |
---|
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.
event | The key event to execute. |
---|
Fling the scroll view
velocityX | The initial velocity in the X direction. Positive numbers mean that the finger/curor is moving down the screen, which means we want to scroll towards the left. |
---|
Handles scrolling in response to a "home/end" shortcut press. This method will scroll the view to the left or right and give the focus to the leftmost/rightmost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.
direction | the scroll direction: FOCUS_LEFT to go the left of the view or FOCUS_RIGHT to go the right |
---|
Indicates whether this ScrollView's content is stretched to fill the viewport.
Implement this method to intercept all touch screen motion events. This allows you to watch events as they are dispatched to your children, and take ownership of the current gesture at any point.
Using this function takes some care, as it has a fairly complicated interaction with View.onTouchEvent(MotionEvent), and using it requires implementing that method as well as this one in the correct way. Events will be received in the following order:
ev | The motion event being dispatched down the hierarchy. |
---|
Implement this method to handle touch screen motion events.
ev | The motion event. |
---|
Handles scrolling in response to a "page up/down" shortcut press. This method will scroll the view by one page left or right and give the focus to the leftmost/rightmost component in the new visible area. If no component is a good candidate for focus, this scrollview reclaims the focus.
direction | the scroll direction: FOCUS_LEFT to go one page left or FOCUS_RIGHT to go one page right |
---|
Called when a child of this parent wants focus
child | The child of this ViewParent that wants focus. This view will contain the focused view. It is not necessarily the view that actually has focus. |
---|---|
focused | The view that is a descendant of child that actually has focus |
Called when a child of this group wants a particular rectangle to be positioned onto the screen. ViewGroups overriding this can trust that:
ViewGroups overriding this should uphold the contract:
child | The direct child making the request. |
---|---|
rectangle | The rectangle in the child's coordinates the child wishes to be on the screen. |
immediate | True to forbid animated or delayed scrolling, false otherwise |
Call this when something has changed which has invalidated the layout of this view. This will schedule a layout pass of the view tree.
Set the scrolled position of your view. This will cause a call to onScrollChanged(int, int, int, int) and the view will be invalidated.
This version also clamps the scrolling to the bounds of our child.
x | the x position to scroll to |
---|---|
y | the y position to scroll to |
Indicates this ScrollView whether it should stretch its content width to fill the viewport or not.
fillViewport | True to stretch the content's width to the viewport's boundaries, false otherwise. |
---|
Set whether arrow scrolling will animate its transition.
smoothScrollingEnabled | whether arrow scrolling will animate its transition |
---|
Like scrollBy(int, int), but scroll smoothly instead of immediately.
dx | the number of pixels to scroll by on the X axis |
---|---|
dy | the number of pixels to scroll by on the Y axis |
Like scrollTo(int, int), but scroll smoothly instead of immediately.
x | the position where to scroll on the X axis |
---|---|
y | the position where to scroll on the Y axis |
The scroll range of a scroll view is the overall width of all of its children.
Compute the amount to scroll in the X 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).
rect | The rect. |
---|
Returns the strength, or intensity, of the left faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.
Returns the strength, or intensity, of the right faded edge. The strength is a value between 0.0 (no fade) and 1.0 (full fade). The default implementation returns 0.0 or 1.0 but no value in between. Subclasses should override this method to provide a smoother fade transition when scrolling occurs.
Ask one of the children of this view to measure itself, taking into account both the MeasureSpec requirements for this view and its padding. The heavy lifting is done in getChildMeasureSpec.
child | The child to measure |
---|---|
parentWidthMeasureSpec | The width requirements for this view |
parentHeightMeasureSpec | The height requirements for this view |
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. The child must have MarginLayoutParams The heavy lifting is done in getChildMeasureSpec.
child | The child to measure |
---|---|
parentWidthMeasureSpec | The width requirements for this view |
widthUsed | Extra space that has been used up by the parent horizontally (possibly by other children of the parent) |
parentHeightMeasureSpec | The height requirements for this view |
heightUsed | Extra space that has been used up by the parent vertically (possibly by other children of the parent) |
Called from layout when this view should assign a size and position to each of its children. Derived classes with children should override this method and call layout on each of their their children.
changed | This is a new size or position for this view |
---|---|
l | Left position, relative to parent |
t | Top position, relative to parent |
r | Right position, relative to parent |
b | Bottom position, relative to parent |
Measure the view and its content to determine the measured width and the measured height. This method is invoked by measure(int, int) and should be overriden by subclasses to provide accurate and efficient measurement of their contents.
CONTRACT: When overriding this method, you
must call setMeasuredDimension(int, int) to store the
measured width and height of this view. Failure to do so will trigger an
IllegalStateException
, thrown by
measure(int, int). Calling the superclass'
onMeasure(int, int) is a valid use.
The base class implementation of measure defaults to the background size, unless a larger size is allowed by the MeasureSpec. Subclasses should override onMeasure(int, int) to provide better measurements of their content.
If this method is overridden, it is the subclass's responsibility to make sure the measured height and width are at least the view's minimum height and width (getSuggestedMinimumHeight() and getSuggestedMinimumWidth()).
widthMeasureSpec | horizontal space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
---|---|
heightMeasureSpec | vertical space requirements as imposed by the parent. The requirements are encoded with View.MeasureSpec. |
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.
direction | One of FOCUS_UP, FOCUS_DOWN, FOCUS_LEFT, and FOCUS_RIGHT |
---|---|
previouslyFocusedRect | The rectangle (in this View's coordinate system) to give a finer grained hint about where focus is coming from. May be null if there is no hint. |
This is called during layout when the size of this view has changed. If you were just added to the view hierarchy, you're called with the old values of 0.
w | Current width of this view. |
---|---|
h | Current height of this view. |
oldw | Old width of this view. |
oldh | Old height of this view. |