I. Overview
This class encapsulates the scrolling operation. Use this class to get the data used to create a scrolling animation-for example, to respond to a swipe gesture.
Scroller tracks the scrolling offset (relative origin) at any time, but does not automatically apply these location information to our view.
Typically, the Computescrolleroffset () method is used to monitor the vertical and lateral deviations of the scroll, which returns a Boolean value that determines whether the scrolling animation is complete (true indicates that the animation has not been completed), which can be used to obtain an offset from the current position, such as
1 PrivateScroller Mscroller =NewScroller (context);2 3 4 if(Mscroller.computescrolloffset ()) {5 //get current horizontal and vertical position (relative origin (0,0))
6 intCurrx =Mscroller.getcurrx ();7 intCurrY =Mscroller.getcurry ();8 ...9}
Second, the structure function:
Public Scroller (Context context)
Create a scroller with the default duration (250ms) and the animation insert
Public Scroller (context context, interpolator interpolator)
Creates a scroller with a specific animation insert, using the default value if the corresponding parameter interpolator is empty
Iii. Public methods
1. public void Abortanimation ()
Aborts the animation. In contrast to Forcefinished (Boolean), stops the animation when scrolling to the end point coordinates.
2. Public boolean computescrolleroffset ()
Calculates the rolling offset. This method is called when you want to get new coordinate information, which is similar to the idea of computecurrentvelocity () in Android.view.VelocityTracker--calling a method to get the program to calculate, and then using other methods to get the results of the calculation. The difference is that scroller needs to determine if there is a scrolling action in progress, and a return value of TRUE indicates that the scroll is not completed (the current direction offset can be obtained), otherwise it is not possible to write related operations, such as the above code.
3. public void extendduration (int extend)
Extend the duration of the animation. When used with SETFINALX (int) and setfinaly (int), you can make the action last longer and slide longer. The parameter extend is in milliseconds.
It's time to sleep and not affect the rest of the roommate ...
Android.widget.Scroller