Example usage for android.view View computeScroll

List of usage examples for android.view View computeScroll

Introduction

In this page you can find the example usage for android.view View computeScroll.

Prototype

public void computeScroll() 

Source Link

Document

Called by a parent to request that a child update its values for mScrollX and mScrollY if necessary.

Usage

From source file:ti.modules.titanium.ui.widget.TiUIScrollView.java

public void scrollTo(int x, int y, boolean smoothScroll) {
    // Fetch the scroll view.
    final View view = this.scrollView;
    if (view == null) {
        return;/*from  ww  w  .  j a v a  2 s  . c o  m*/
    }

    // Convert the given coordinates to pixels.
    x = TiConvert.toTiDimension(x, -1).getAsPixels(view);
    y = TiConvert.toTiDimension(y, -1).getAsPixels(view);

    // Disable smooth scrolling for vertical scroll views if not at top of view.
    // Note: This works-around a bug in Google's NestedScrollView where attempting to
    //       smooth scrolls will move to a totally different position or opposite directions.
    if (smoothScroll && (view instanceof TiVerticalScrollView)) {
        if (((TiVerticalScrollView) view).getScrollY() > 0) {
            smoothScroll = false;
        }
    }

    // Scroll to the given position.
    if (smoothScroll) {
        if (view instanceof TiHorizontalScrollView) {
            ((TiHorizontalScrollView) view).smoothScrollTo(x, y);
        } else if (view instanceof TiVerticalScrollView) {
            ((TiVerticalScrollView) view).smoothScrollTo(x, y);
        }
    } else {
        view.scrollTo(x, y);
    }
    view.computeScroll();
}