An overview of Scrollby and Scrollto of Android development

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.