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