ScrollView Inheritance Relationship ScrollView Source location Android.widget.ScrollView, the view class is mainly inherited and Framelayout
public class ScrollView extends Framelayout
Java.lang.Object
Android.view.View
Android.view.ViewGroup
Android.widget.FrameLayout
Android.widget.ScrollView
class overview
A hierarchical layout container that allows users to scroll, allowing more content to be displayed than they actually are. ScrollView is a framelayout that means that you need to place a child element on it that has its own scrolling content. A child element can be a layout manager for a complex object. The normally used child element is the vertical direction of the linearlayout, which displays the arrows in the topmost vertical direction that allows the user to scroll.
The TextView class also has its own scrolling function, so there is no need to use ScrollView, but only two combinations can guarantee the efficiency when more content is displayed. But only a combination of the two can be implemented in a larger container with a text view effect.
ScrollView only supports scrolling in the vertical direction.
constructor function
Public ScrollView (Context context)
Creates a ScrollView instance of a default property.
Public ScrollView (context context, AttributeSet attrs)
Creates a ScrollView instance with the Attrs property.
Public ScrollView (context context, AttributeSet attrs, int defstyle)
Creates a ScrollView instance with the Attrs property and specifies its default style.
Public methods
public void AddView (View child)
Add a child view. If the layout parameter is not set for the child view beforehand, the child view is set with the default parameters of the current viewgroup.
Parameters
Child view added by
public void AddView (View child, int index)
Add a child view. If the layout parameter is not set for the child view beforehand, the child view is set with the default parameters of the current viewgroup.
Parameters
Child view added by
Index Add the location of the child view
public void AddView (View child, int index, viewgroup.layoutparams params)
Adds a child view based on the specified layout parameter
Parameters
Child view added by
Index Add the location of the child view
The layout parameter that the params sets for the child view
public void AddView (View child, Viewgroup.layoutparams params)
Adds a child view based on the specified layout parameter.
Parameters
Child view added by
The layout parameter that the params sets for the child view
public boolean arrowscroll (int direction)
Handles scrolling on scroll bars when the up and down arrows are clicked.
Parameters
Direction the direction of the arrow that is pressed
return value
If we handle (consume) This event returns true, otherwise false is returned.
public void Computescroll ()
Called by the parent view to update the values of its child views (MSCROLLX and mscrolly) when necessary. A typical case is that a child view in the parent view uses a Scroller object for scrolling, which makes this method called.
public boolean dispatchkeyevent (KeyEvent event)
Sends a key event to the next view of the current focus path. This focus path is executed from the top level of the view tree until the current focus view. If this view is the focus view, it will be sent for itself. Otherwise, it is sent for the next node of the current focus path. This method also provokes a key listener.
Parameters
Event sent by key
return value
The event is processed to return true, otherwise false is returned.
public void Draw (canvas canvas)
Manually draw the view (and its child view) to the specified canvas. This view must be in the overall layout before calling this function. When implementing a view, you do not need to inherit this method; instead, you should implement the OnDraw (Canvas) method.
Parameters
Canvas for drawing views on canvas
public boolean executekeyevent (KeyEvent event)
When the key event is received, the user can call this function to make the scrolling view perform scrolling, similar to handling events sent by the view system.
Parameters
Event requires execution of key events
return value
The event is processed to return true, otherwise false is returned.
public void Fling (int velocityy)
Slide (Fling) gesture of the scrolling view. (Translator Note: How to monitor the Android screen slide stop event)
Parameters
Velocityy the initial rate in the Y direction. A positive value indicates that the finger/cursor is sliding toward the bottom of the screen, and the content scrolls up.
public boolean fullscroll (int direction)
Respond to "Home/end" on a short, timely response to rolling processing. This method scrolls the view to the top or bottom and places the focus on the topmost/bottommost component of the new viewable area. If there are no suitable components to focus on, the current scrollview will retract the focus.
Parameters
Direction Scroll Direction: Focus_up indicates that the view scrolls up; Focus_down indicates that the view scrolls down
return value
If the key event is consumed (consumed) returns true, other conditions return false.
public int Getmaxscrollamount ()
return value
The maximum number of current scrolling view response arrow events that can scroll.
public boolean isfillviewport ()
Indicates whether the contents of the current scrollview are stretched to fill the view visual range (Translator Note: Viewport visual range, see determining the visual range of the control within the ScrollViewer).
return value
The content Fill view returns True, otherwise false is returned.
public boolean issmoothscrollingenabled ()
return value
Whether scrolling is displayed as a smooth effect when scrolling in the direction of the arrow.
public boolean onintercepttouchevent (motionevent ev)
This method is implemented to intercept all motion events when touching the screen. You can monitor these events as you do with events sent to a child view, and get the ownership of the current gesture at any point
You need to be aware of this approach, because it has a fairly complex interaction with view.ontouchevent (motionevent), and the premise needs to be performed correctly view.ontouchevent (motionevent). The events are received in the following order:
1. Received the Down event
2. The down event is either handled by a sub-view of the view group or handled by the user's own Ontouchevent () method, which means that you should perform ontouchevent () to return true so that you can continue to see the remaining gestures (instead of looking for a parent view processing). If Ontouchevent () returns True, you do not receive any events for onintercepttouchevent () and all touch processing must occur in ontouchevent ().
3. If this method returns False, the next event (up to and including the final up) will be first passed as this, then the target's ontouchevent ().
4. If you return true, you will not receive any of the following events: The target view will receive the same event but will accompany Action_cancel, and all further events will be passed to your own ontouchevent () method and will not appear here.
Parameters
Action events sent down by EV system
return value
Returns true if a motion event is intercepted from a child view and sent through Ontouchevent () to the current viewgroup. The current target will receive the Action_cancel event, and no more messages will be delivered to this.
、
public boolean ontouchevent (motionevent ev)
Perform this method in order to handle the motion events of the touch screen.
Parameters
EV Motion Events
return value
The event is processed to return true, and the other returns false.
public boolean pagescroll (int direction)
Response to a short press of "page Up/down" when scrolling is processed. This method scrolls up or down one screen and places the focus at the top/bottom of the new viewable area. If there is no suitable component as the focus, the current ScrollView will retract the focus.
Parameters
Direction scrolling direction: Focus_up means flipping up one page, focus_down means flipping down one page.
return value
This key event is consumed (cosumed) to return True, and the other returns false.
public void Requestchildfocus (view child, view focused)
This method is called when a child view of the parent view is to get the focus.
Parameters
Child view of the parent view for which to get the focus. This view contains the focus view. This view is actually the focus view if there is no special requirement for Xu.
Descendants view of the focused child view and this descendant view is the true focus view
public boolean Requestchildrectangleonscreen (View child, Rect Rectangle, Boolean immediate)
This method is called when a child view in a group needs to be positioned on a rectangular range of the screen. The viewgroup of this method can be overloaded to confirm the following points:
* Sub-item will be the immediate child in the group
* The rectangle will be in the coordinate system of the sub-project
Overloading the ViewGroup of this method should support the following points:
* If the rectangle is already visible, nothing will change.
* To make the rectangular area visible, the view can be scrolled
Parameters
Child view of request made
Rectangle a rectangle within the coordinate system of a subproject, that is, the sub-project wants to position on the screen
Immediate set to true to prevent animation and smooth movement of scrollbars
return value
The group in which the scroll was performed, whether to handle this operation.
public void Requestlayout ()
This function is called when there is a change that causes the current view to be re-laid. It will plan the layout path of a view tree.
public void ScrollTo (int x, int y)
Sets the position where the current view is scrolled. This function causes a call to the onscrollchanged (int, int, int, int) function and causes the view to be updated.
The current version cancels scrolling in the child view.
Parameters
x scroll to the X position
Y scroll to the Y position
public void Setfillviewport (Boolean fillviewport)
Sets whether the current scrolling view stretches the content height to fill the view visual range (Translator Note: Viewport visual range, see determining the visual range of the control inside the ScrollViewer).
Parameters
Fillviewport is set to true to indicate the height of the extruded content to accommodate the viewport boundaries;
public void Setoverscrollmode (int mode)
Sets the Over-scroll mode for the view. Valid Over-scroll mode has over_scroll_always (default), Over_scroll_if_content_scrolls (only allows over-scrolling when the view content is larger than the container) and Over_ Scroll_never. This setting only works if the view can be scrolled.
(Translator Note: This function is new in 2.3 r1, API level 9.) About Over-scroll This is translated as elastic scrolling, ie, see the post: An iphone-like elastic listview Scroll)
Parameters
Mode the new Over-scroll mode for this view.
public void Setsmoothscrollingenabled (Boolean smoothscrollingenabled)
Used to set whether the arrow scrolling can cause the view to scroll.
Parameters
Smoothscrollingenabled sets the bool value of whether the arrow scrolling can cause content to scroll
Public final void Smoothscrollby (int dx, int dy)
Similar to Scrollby (int, int), but scrolling is flat rather than immediately scrolled to somewhere.
Parameters
Number of pixels that DX scrolls in x direction
Number of pixels that dy scrolls in the y direction
Public final void Smoothscrollto (int x, int y)
Similar to Scrollto (int, int), but scrolling is flat rather than immediately scrolled to somewhere.
Parameters
x the X coordinate to scroll to the position
Y to scroll to the position y-coordinate
Protected method
protected int Computescrolldeltatogetchildrectonscreen (rect rect)
Calculates the sum of the X-direction scrolling so that the full rectangle of the child view is displayed on the screen (or at least the first screen size is filled if the rectangle is wider than the screen width).
Parameters
Rect rectangle
return value
Scrolling difference value
protected int Computeverticalscrolloffset ()
Calculates the offset of the slider for the vertical scroll bar. This value is used to calculate the position of the slider for the scroll bar track.
The range can be expressed in any unit, but must be consistent with the units of Computeverticalscrollrange () and Computeverticalscrollextent ().
The default offset is the offset at which the current view scrolls.
return value
The offset in the vertical direction of the slider bar.
protected int Computeverticalscrollrange ()
The scrollable extent of a scrolling view is the height of all child elements.
return value
All vertical extents represented by the vertical scroll bar, the default range is the drawing height of the current view.
protected float getbottomfadingedgestrength ()
Returns the visibility at the bottom of the scroll. The range of visibility values is 0.0 (not disappearing) to 1.0 (completely disappearing) between. The default execution return value is 0.0 or 1.0, not one of their middle values. Subclasses need to overload this method to provide a gentle fade implementation when scrolling.
return value
Scrolling bottom visibility, the value range is between floating point numbers 0.0f to 1.0f.
protected float gettopfadingedgestrength ()
Returns the visibility at the top of the scroll. The range of visibility values is 0.0 (not disappearing) to 1.0 (completely disappearing) between. The default execution return value is 0.0 or 1.0, not one of their middle values. Subclasses need to overload this method to provide a gentle fade implementation when scrolling.
return value
Scrolling top visibility, values range from 0.0f to 1.0f floating point.
protected void Measurechild (View child, int parentwidthmeasurespec, int parentheightmeasurespec)
Requires a child view of the current view to measure itself, taking into account the MEASURESPEC requirements of the current view and its whitespace. The child view must have marginlayoutparams. The more complicated work is done in the Getchildmeasurespec.
Parameters
Child needs to measure its own sub-view
Parentwidthmeasurespec the width required for the current view
Parentheightmeasurespec the width required for the current view
protected void Measurechildwithmargins (View child, int parentwidthmeasurespec, int widthused, int Parentheightmeasurespec, int heightused)
Requires a child view of the current view to measure itself, taking into account the MEASURESPEC requirements of the current view and its gaps and boundaries. The child view must have marginlayoutparams. The more complicated work is done in the Getchildmeasurespec.
Parameters
Child needs to measure sub-view
Parentwidthmeasurespec the width required for the current view
Widthused The white space that is used by the parent view in the horizontal direction (it may also be used by the other child views of the view)
Parentheightmeasurespec the width required for the current view
Heightused The white space used by the parent view in the vertical direction (or possibly other child views of the view)
protected void OnLayout (Boolean changed, int l, int t, int r, int b)
The current view needs to allocate the size and position of the child view when called, and the subclass inherits the layout function that must overload this method and invoke its own child view.
Parameters
Changed the new size or position of the current view
L relative to Parent view, left border position
T relative to Parent view, upper boundary position
R relative to Parent view, right border position
b relative to Parent view, bottom boundary position
protected void onmeasure (int widthmeasurespec, int heightmeasurespec)
Measure the view to determine its content width and height. This method is called by measure (int, int). A quilt class rewrite is required to provide accurate and efficient measurements of its content.
Convention: When overriding this method, you must call setmeasureddimension (int, int) to save the current view's width and height. Unsuccessful calls to this method will result in a IllegalStateException exception that is thrown by measure (int, int). So it is necessary to call the onmeasure (int, int) method of the parent class.
The implementation of the parent class is based on the default size of the background size, unless the measurespec (measure rule) allows for a larger background. Subclasses can override Onmeasure (Int,int) to provide better dimensions for their content.
If this method is overridden, then the responsibility of the subclass is to confirm that the measurement height and measurement width are greater than the minimum width and minimum height of the view (Getsuggestedminimumheight () and Getsuggestedminimumwidth ()). Use these two methods to achieve the minimum width and minimum height.
Parameters
The Widthmeasurespec is subject to the horizontal space required by the main window. This requirement is encoded by VIEW.MEASURESPEC.
The Heightmeasurespec is subject to the vertical space required by the main window. This requirement is encoded by VIEW.MEASURESPEC.
protected void onoverscrolled (int scrollx, int scrolly, Boolean clampedx, Boolean clampedy)
Called by a overscrollby (int, int, int, int, int, int, int, int, Boolean) to respond to the result of a over-scroll operation. (Translator Note: This function is new in 2.3 r1, API level 9)
Parameters
SCROLLX New X-scrolling pixel values
scrolly New Y-scrolling pixel values
Clampedx The value is true when Scrollx is bounded by the over-scroll boundary
Clampedy The value is true when scrolly is bounded by the over-scroll boundary
protected Boolean onrequestfocusindescendants (int direction, Rect previouslyfocusedrect)
When you find the focus view in a child view of a scrolling view, you need to be careful not to set the focus on a control that scrolls out of the screen. This method is more expensive than executing the default viewgroup, otherwise this behavior is also set to the default
Parameters
direction specifies one of the following constants: Focus_up, Focus_down, Focus_left, Focus_right
Previouslyfocusedrect can give a better hint of the rectangle (the current view of the coordinate system) to indicate where the focus is derived. Null if no prompt is indicated.
return value
Whether the focus has been achieved
protected void onsizechanged (int w, int h, int oldw, int oldh)
Called when the size of the view has changed during layout. If you just add to the view, the old value of 0 is displayed when the call is called. (Translator note: When added to the view, OLDW and OLDH return 0).
Parameters
W View current width
H View current Height
OLDW width before the view changes
OLDH height before the view changes
Android Control Chapter View Control ScrollView Explore