Android View Scroller

Source: Internet
Author: User

When you inherit the view control override control functionality, you often scroll through the contents of the control, and then you need to invoke one of the two methods of view content movement:
View.scrollby (int x, int y) and smooth content scrolling to the target coordinates (visible move effect)
View.scrollto (int x, int y)-the content is immediately scrolled to the target coordinates (teleport!?). )


When scrolling, you also need to determine whether the scrolling content is more than the display bounds, at this point to call to two methods to get the scrolling distance (it is important to note that the view is the upper left corner of the coordinate origin (0,0)),
Method: View.getscrollx () to get the horizontal coordinate movement distance
View.getscrolly ()-Get vertical coordinate movement distance
Such as:
1. Swipe to the right, and the content scrolls left, View.getscrollx () gets a negative value
2. Swipe left with the content scrolling to the right, and VIEW.GETSCROLLX () has a positive value
3. Swipe down, and the content scrolls up, view.getscrolly () gets a negative value
4. Swipe up, and the content scrolls down, view.getscrolly () gets a positive value
In short, the direction of the finger slide is opposite to the content scrolling, and the interface effect of the ListView and Horizontalscrollview is known
After you get the value, you can scroll through (new Scroller ()). Startscroll (int startX, int starty, int dx, int dy) method scrolls the content to the appropriate location
To perform a scroller scrolling response in the override method of the view:

@Override      Public void Computescroll () {        if  (Scroller.computescrolloffset ()) {            //  The following condition is called because the scroller called the slide so that it fires             scrollTo (Scroller.getcurrx (), Scroller.getcurry ());            Invalidate ();             return ;        }         Super . Computescroll ();    }



Android View Scroller

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.