Example usage for android.widget ScrollView setScrollY

List of usage examples for android.widget ScrollView setScrollY

Introduction

In this page you can find the example usage for android.widget ScrollView setScrollY.

Prototype

public void setScrollY(int value) 

Source Link

Document

Set the vertical scrolled position of your view.

Usage

From source file:org.catrobat.paintroid.ui.BottomBar.java

private void startBottomBarAnimation() {
    final HorizontalScrollView horizontalScrollView = (HorizontalScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_scroll_view);
    final ScrollView verticalScrollView = (ScrollView) mMainActivity
            .findViewById(R.id.bottom_bar_landscape_scroll_view);
    final int animationDuration = 1000;
    int orientation = mMainActivity.getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_PORTRAIT) {
        horizontalScrollView.post(new Runnable() {
            public void run() {
                int scrollToX = (int) (getToolButtonByToolType(mCurrentToolType).getX()
                        - horizontalScrollView.getWidth() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_button_width) / 2.0f);
                int scrollFromX = PaintroidApplication.isRTL ? horizontalScrollView.getChildAt(0).getLeft()
                        : horizontalScrollView.getChildAt(0).getRight();
                horizontalScrollView.setScrollX(scrollFromX);
                ObjectAnimator.ofInt(horizontalScrollView, "scrollX", scrollToX).setDuration(animationDuration)
                        .start();//from w  ww. j  av  a2  s. c  o m
            }
        });
    } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        verticalScrollView.post(new Runnable() {
            public void run() {
                int scrollToY = (int) (getToolButtonByToolType(mCurrentToolType).getY()
                        - verticalScrollView.getHeight() / 2.0f
                        + mMainActivity.getResources().getDimension(R.dimen.bottom_bar_landscape_button_height)
                                / 2.0f);
                int scrollFromY = verticalScrollView.getChildAt(0).getBottom();
                verticalScrollView.setScrollY(scrollFromY);
                ObjectAnimator.ofInt(verticalScrollView, "scrollY", scrollToY).setDuration(animationDuration)
                        .start();
            }
        });
    }

    delayedAnimateSelectedTool(animationDuration);
}