java.lang.Object | |
↳ | android.widget.Scroller |
This class encapsulates scrolling. You can use scrollers (Scroller
or OverScroller
) to collect the data you need to produce a scrolling
animation—for example, in response to a fling gesture. Scrollers track
scroll offsets for you over time, but they don't automatically apply those
positions to your view. It's your responsibility to get and apply new
coordinates at a rate that will make the scrolling animation look smooth.
Here is a simple example:
private Scroller mScroller = new Scroller(context); ... public void zoomIn() { // Revert any animation currently in progress mScroller.forceFinished(true); // Start scrolling by providing a starting point and // the distance to travel mScroller.startScroll(0, 0, 100, 0); // Invalidate to request a redraw invalidate(); }
To track the changing positions of the x/y coordinates, use
computeScrollOffset()
. The method returns a boolean to indicate
whether the scroller is finished. If it isn't, it means that a fling or
programmatic pan operation is still in progress. You can use this method to
find the current offsets of the x and y coordinates, for example:
if (mScroller.computeScrollOffset()) { // Get current x and y positions int currX = mScroller.getCurrX(); int currY = mScroller.getCurrY(); ... }
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Create a Scroller with the default duration and interpolator.
| |||||||||||
Create a Scroller with the specified interpolator.
| |||||||||||
Create a Scroller with the specified interpolator.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Stops the animation.
| |||||||||||
Call this when you want to know the new location.
| |||||||||||
Extend the scroll animation.
| |||||||||||
Start scrolling based on a fling gesture.
| |||||||||||
Force the finished field to a particular value.
| |||||||||||
Returns the current velocity.
| |||||||||||
Returns the current X offset in the scroll.
| |||||||||||
Returns the current Y offset in the scroll.
| |||||||||||
Returns how long the scroll event will take, in milliseconds.
| |||||||||||
Returns where the scroll will end.
| |||||||||||
Returns where the scroll will end.
| |||||||||||
Returns the start X offset in the scroll.
| |||||||||||
Returns the start Y offset in the scroll.
| |||||||||||
Returns whether the scroller has finished scrolling.
| |||||||||||
Sets the final position (X) for this scroller.
| |||||||||||
Sets the final position (Y) for this scroller.
| |||||||||||
The amount of friction applied to flings.
| |||||||||||
Start scrolling by providing a starting point and the distance to travel.
| |||||||||||
Start scrolling by providing a starting point, the distance to travel,
and the duration of the scroll.
| |||||||||||
Returns the time elapsed since the beginning of the scrolling.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create a Scroller with the default duration and interpolator.
Create a Scroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used. "Flywheel" behavior will be in effect for apps targeting Honeycomb or newer.
Create a Scroller with the specified interpolator. If the interpolator is null, the default (viscous) interpolator will be used. Specify whether or not to support progressive "flywheel" behavior in flinging.
Stops the animation. Contrary to forceFinished(boolean)
,
aborting the animating cause the scroller to move to the final x and y
position
Call this when you want to know the new location. If it returns true, the animation is not yet finished.
Extend the scroll animation. This allows a running animation to scroll
further and longer, when used with setFinalX(int)
or setFinalY(int)
.
extend | Additional time to scroll in milliseconds. |
---|
Start scrolling based on a fling gesture. The distance travelled will depend on the initial velocity of the fling.
startX | Starting point of the scroll (X) |
---|---|
startY | Starting point of the scroll (Y) |
velocityX | Initial velocity of the fling (X) measured in pixels per second. |
velocityY | Initial velocity of the fling (Y) measured in pixels per second |
minX | Minimum X value. The scroller will not scroll past this point. |
maxX | Maximum X value. The scroller will not scroll past this point. |
minY | Minimum Y value. The scroller will not scroll past this point. |
maxY | Maximum Y value. The scroller will not scroll past this point. |
Force the finished field to a particular value.
finished | The new finished value. |
---|
Returns the current velocity.
Returns the current X offset in the scroll.
Returns the current Y offset in the scroll.
Returns how long the scroll event will take, in milliseconds.
Returns where the scroll will end. Valid only for "fling" scrolls.
Returns where the scroll will end. Valid only for "fling" scrolls.
Returns the start X offset in the scroll.
Returns the start Y offset in the scroll.
Returns whether the scroller has finished scrolling.
Sets the final position (X) for this scroller.
newX | The new X offset as an absolute distance from the origin. |
---|
Sets the final position (Y) for this scroller.
newY | The new Y offset as an absolute distance from the origin. |
---|
The amount of friction applied to flings. The default value
is getScrollFriction()
.
friction | A scalar dimension-less value representing the coefficient of friction. |
---|
Start scrolling by providing a starting point and the distance to travel. The scroll will use the default value of 250 milliseconds for the duration.
startX | Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left. |
---|---|
startY | Starting vertical scroll offset in pixels. Positive numbers will scroll the content up. |
dx | Horizontal distance to travel. Positive numbers will scroll the content to the left. |
dy | Vertical distance to travel. Positive numbers will scroll the content up. |
Start scrolling by providing a starting point, the distance to travel, and the duration of the scroll.
startX | Starting horizontal scroll offset in pixels. Positive numbers will scroll the content to the left. |
---|---|
startY | Starting vertical scroll offset in pixels. Positive numbers will scroll the content up. |
dx | Horizontal distance to travel. Positive numbers will scroll the content to the left. |
dy | Vertical distance to travel. Positive numbers will scroll the content up. |
duration | Duration of the scroll in milliseconds. |
Returns the time elapsed since the beginning of the scrolling.