Example usage for android.widget OverScroller setFriction

List of usage examples for android.widget OverScroller setFriction

Introduction

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

Prototype

public final void setFriction(float friction) 

Source Link

Document

The amount of friction applied to flings.

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
    );/*w  w  w  .  ja  va2s  . co  m*/
    return scroller.getFinalX();
}

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

private int predictFinalScrollPosition(int velocityY) {
    // 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 = getMaxScrollY();
    int height = getHeight() - getPaddingBottom() - getPaddingTop();
    scroller.fling(getScrollX(), // startX
            getScrollY(), // startY
            0, // velocityX
            velocityY, // velocityY
            0, // minX
            0, // maxX
            0, // minY
            maximumOffset, // maxY
            0, // overX
            height / 2 // overY
    );/*from   w ww . ja v  a2 s  . com*/
    return scroller.getFinalY();
}