Example usage for android.widget OverScroller getFinalX

List of usage examples for android.widget OverScroller getFinalX

Introduction

In this page you can find the example usage for android.widget OverScroller getFinalX.

Prototype

public final int getFinalX() 

Source Link

Document

Returns where the scroll will end.

Usage

From source file:com.facebook.react.views.scroll.ReactHorizontalScrollView.java

private int predictFinalScrollPosition(int velocityX) {
    // ScrollView can *only* scroll for 250ms when using smoothScrollTo and there's
    // no way to customize the scroll duration. So, we create a temporary OverScroller
    // so we can predict where a fling would land and snap to nearby that point.
    OverScroller scroller = new OverScroller(getContext());
    scroller.setFriction(1.0f - mDecelerationRate);

    // predict where a fling would end up so we can scroll to the nearest snap offset
    int maximumOffset = Math.max(0, computeHorizontalScrollRange() - getWidth());
    int width = getWidth() - getPaddingStart() - getPaddingEnd();
    scroller.fling(getScrollX(), // startX
            getScrollY(), // startY
            velocityX, // velocityX
            0, // velocityY
            0, // minX
            maximumOffset, // maxX
            0, // minY
            0, // maxY
            width / 2, // overX
            0 // overY
    );//from   w w w. ja v a  2s .  com
    return scroller.getFinalX();
}