Android7.0中文文档(API)-- Scroller

来源:互联网 发布:关于茶的软件 编辑:程序博客网 时间:2024/06/02 06:47

 完整内容,请查看:http://www.zhdoc.net/android/reference/android/widget/Scroller.html

Scroller

public class Scroller
extends Object

java.lang.Object   ↳android.widget.Scroller

This class encapsulates scrolling. You can use scrollers (Scroller orOverScroller) 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.
这个类封装了滚动行为。您可以使用滚动条(ScrollerOverScroller)来收集所需的数据,以生成滚动的动画,例如,对fling的手势进行响应。随着时间的推移,滚动条会为你跟踪滚动的偏移量,但它们不会自动将这些位置设置到你的视图中。你的责任是获取和设置新的坐标,以使滚动的动画看起来平滑。

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:
为了跟踪X/Y坐标的位置改变,请使用computeScrollOffset()方法。该方法返回一个布尔值,以指示是否完成了滚动。如果不是这样,那就意味着一个fling或编程的操作仍然在进行中。你可以调用此方法来查找当前的X和Y坐标的偏移,例如:

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

摘要


Public构造方法

Scroller(Context context)

Create a Scroller with the default duration and interpolator.
使用默认的持续时间和插值器来创建一个Scroller对象。

Scroller(Context context, Interpolator interpolator)

Create a Scroller with the specified interpolator.
使用指定的插值器来创建一个Scroller对象。

Scroller(Context context, Interpolator interpolator, boolean flywheel)

Create a Scroller with the specified interpolator.
使用指定的插值器来创建一个Scroller对象。

原创粉丝点击