Android Guides | Samples

Android.Widget.Scroller Class

java 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();
 }

java Example

if (mScroller.computeScrollOffset()) {
     // Get current x and y positions
     int currX = mScroller.getCurrX();
     int currY = mScroller.getCurrY();
    ...
 }

See Also: Scroller

Syntax

[Android.Runtime.Register("android/widget/Scroller", DoNotGenerateAcw=true)]
public class Scroller : Object

Remarks

java 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();
 }

java Example

if (mScroller.computeScrollOffset()) {
     // Get current x and y positions
     int currX = mScroller.getCurrX();
     int currY = mScroller.getCurrY();
    ...
 }

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:

To track the changing positions of the x/y coordinates, use Scroller.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:

[Android Documentation]

Requirements

Namespace: Android.Widget
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Android.Widget.Scroller are listed below.

See Also: Object

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.

Protected Constructors

A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
CurrVelocitySingle. Returns the current velocity.
[read-only]
CurrXInt32. Returns the current X offset in the scroll.
[read-only]
CurrYInt32. Returns the current Y offset in the scroll.
[read-only]
DurationInt32. Returns how long the scroll event will take, in milliseconds.
FinalXInt32. Returns where the scroll will end.
FinalYInt32. Returns where the scroll will end.
[read-only]
IsFinishedBoolean. Returns whether the scroller has finished scrolling.
[read-only]
StartXInt32. Returns the start X offset in the scroll.
[read-only]
StartYInt32. Returns the start Y offset in the scroll.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

AbortAnimation()
Stops the animation.
ComputeScrollOffset() : Boolean
Call this when you want to know the new location.
ExtendDuration(Int32)
Extend the scroll animation.
Fling(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32)
Start scrolling based on a fling gesture.
ForceFinished(Boolean)
Force the finished field to a particular value.
SetFriction(Single)
The amount of friction applied to flings.
StartScroll(Int32, Int32, Int32, Int32)
Start scrolling by providing a starting point and the distance to travel.
StartScroll(Int32, Int32, Int32, Int32, Int32)
Start scrolling by providing a starting point, the distance to travel, and the duration of the scroll.
TimePassed() : Int32
Returns the time elapsed since the beginning of the scrolling.