Just in learning listview sliding Delete, to use the view of the Scrollby and Scrollto, on the study, the following share:
First say Scrollto,
Scrollto (int x, int y): incoming x,y coordinates, move view to (-x,-y) position
Scrollby (int x, int y): incoming x,y coordinates, move view to x positive direction, move y unit
If x is a positive number, move to the left, or to the right
Here's a picture, for example:
Red box on behalf of the mobile phone interface, black box on behalf of a linearlayout,id set for llayout;
The following calls:
Llayout.scrollto ( -100,0);
Effect:
Call Llayout.scrollto ( -100,0) again at this time; the image is not going to change because the function of this method is to move to a fixed point
Well, this time again called: Llayout.scrollby ( -100,0);
The image will become this way:
Which moves the 100px to the right,
This time the assumption calls Llayout.scrollto (0,0); he's going back to the original position.
See the Scrollby method can be seen:
Scrollby is also the method that invokes the Scrollto, and the parameter is the current scroll coordinate plus the incoming coordinates, that is, moving from the current position (x,y)
public void Scrollby (int x, int y) {
Scrollto (mscrollx + x, mscrolly + y);
}
Some students may ask, why the parameters are negative, go indeed is a positive direction, this question in the view of the source code can be explained:
public void invalidate (int l, int t, int r, int b) {
Final int scrollx = MSCROLLX;
Final int scrolly = mscrolly;
Invalidateinternal (L-SCROLLX, t-scrolly, R-scrollx, b-scrolly, True, false);
}
Negative negative positive, so easy to understand a lot of it, as for why to reduce, you can explore their own
Use popular words to summarize the two methods:
If two people are running, Scrollto ( -50,0) is moved to 50th M, Scrollby ( -50,0) is 50 meters, when two people are at the starting point, the two methods are equivalent