protected int mscrollx; //The view content corresponds to the offset of the start coordinate of the view, x-axis direction
protected int mscrolly; //The view content corresponds to the offset of the start coordinate of the view, y-axis direction
The offset represents the relative position, not the absolute position of the starting point.
Like a point on the road, it is the absolute length from the starting point, and the distance from the halfway point is the offset from the halfway point.
Simple point to metaphor:
You are going to Guangzhou from Beijing, 100 kilometers past Zhengzhou
Zhengzhou is the base address, 100 is offset!
public void ScrollTo (int x, int y)
The display (visible) area is at (x, y) coordinates at the current view content offset to (x, y) coordinates
- Public void ScrollTo ( int x, int y) {
- //Offset position has changed
- if (mscrollx! = x | | mscrolly! = y) {
- int oldx = MSCROLLX;
- int oldY = mscrolly;
- MSCROLLX = x; //Assign new value, save current cheap amount
- mscrolly = y;
- //Callback Onscrollchanged method
- Onscrollchanged (MSCROLLX, mscrolly, OLDX, OldY);
- if (!awakenscrollbars ()) {
- Invalidate (); //generally causes repainting
- }
- }
- }
public void Scrollby (int x, int y)
The contents of the current view continue to offset (x, Y) units, and the display (viewable) area is also offset (x, y) units
- //MSCROLLX and mscrolly represent our current offset position and continue to offset (x, Y) units at the current position
- public void Scrollby ( int x, int y) {
- ScrollTo (mscrollx + x, mscrolly + y);
- }
Understanding of Scrollto and Scrollby in Android