In the latest demo, scrollto and scroller are used to find that the view is rolled to the positive direction of the coordinate axis only when a negative value is passed.
It's hard to understand, because the scrollto annotation is written
* @ Param x the x position to scroll
* @ Param y the y position to scroll
I checked the half-day view code.
Find a possible cause: the code is as follows (just a personal guess)
/**
* Mark the area defined by the rect (l, t, r, B) as needing to be drawn.
* The coordinates of the dirty rect are relative to the view.
* If the view is visible, {@ link # onDraw (android. graphics. Canvas )}
* Will be called at some point in the future. This must be called from
* A UI thread. To call from a non-UI thread, call {@ link # postInvalidate ()}.
* @ Param l the left position of the dirty region
* @ Param t the top position of the dirty region
* @ Param r the right position of the dirty region
* @ Param B the bottom position of the dirty region
*/
Public void invalidate (int l, int t, int r, int B ){
If (skipInvalidate ()){
Return;
}
If (mPrivateFlags & (DRAWN | HAS_BOUNDS) = (DRAWN | HAS_BOUNDS) |
(MPrivateFlags & DRAWING_CACHE_VALID) = DRAWING_CACHE_VALID |
(MPrivateFlags & INVALIDATED )! = INVALIDATED ){
MPrivateFlags & = ~ DRAWING_CACHE_VALID;
MPrivateFlags | = INVALIDATED;
MPrivateFlags | = DIRTY;
Final ViewParent p = mParent;
Final AttachInfo ai = mAttachInfo;
// Noinspection PointlessBooleanExpression, ConstantConditions
If (! HardwareRenderer. RENDER_DIRTY_REGIONS ){
If (p! = Null & ai! = Null & ai. mHardwareAccelerated ){
// Fast-track for GL-enabled applications; just invalidate the whole hierarchy
// With a null dirty rect, which tells the ViewAncestor to redraw everything
P. invalidateChild (this, null );
Return;
}
}
If (p! = Null & ai! = Null & l <r & t <B ){
Final int scrollX = mScrollX;
Final int scrollY = mScrollY;
Final Rect tmip = ai. mTmpInvalRect;
Tmip. set (l-scrollX, t-scrollY, r-scrollX, B-scrollY );
P. invalidateChild (this, tmip );
}
}
}
If the view is visible,onDraw(android.graphics.Canvas)Will be called at some point in the future
That is to say, this method is called before ondraw and a specified rectangle box is provided for the view.
The value of the rectangle is set in this way.
Final int scrollX = mScrollX;
Final int scrollY = mScrollY;
Final Rect tmip = ai. mTmpInvalRect;
Tmip. set (l-scrollX, t-scrollY, r-scrollX, B-scrollY );
P. invalidateChild (this, tmip );
Therefore, scrollto must pass a negative value. Otherwise, the coordinate system of the rectangular box area will move in the negative direction.
So I cannot understand the comment of the view scrollto method.