Java Code Examples for com.github.ksoichiro.android.observablescrollview.ObservableScrollView#scrollTo()

The following examples show how to use com.github.ksoichiro.android.observablescrollview.ObservableScrollView#scrollTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewPagerTabActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void propagateToolbarStateForScrollView(boolean isShown, View view, int toolbarHeight) {
    ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
    if (scrollView == null) {
        return;
    }
    if (isShown) {
        // Scroll up
        if (0 < scrollView.getCurrentScrollY()) {
            scrollView.scrollTo(0, 0);
        }
    } else {
        // Scroll down (to hide padding)
        if (scrollView.getCurrentScrollY() < toolbarHeight) {
            scrollView.scrollTo(0, toolbarHeight);
        }
    }
}
 
Example 2
Source File: ViewPagerTabScrollViewActivity.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void propagateToolbarState(boolean isShown) {
    int toolbarHeight = mToolbarView.getHeight();

    // Set scrollY for the fragments that are not created yet
    mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight);

    // Set scrollY for the active fragments
    for (int i = 0; i < mPagerAdapter.getCount(); i++) {
        // Skip current item
        if (i == mPager.getCurrentItem()) {
            continue;
        }

        // Skip destroyed or not created item
        Fragment f = mPagerAdapter.getItemAt(i);
        if (f == null) {
            continue;
        }

        ObservableScrollView scrollView = (ObservableScrollView) f.getView().findViewById(R.id.scroll);
        if (isShown) {
            // Scroll up
            if (0 < scrollView.getCurrentScrollY()) {
                scrollView.scrollTo(0, 0);
            }
        } else {
            // Scroll down (to hide padding)
            if (scrollView.getCurrentScrollY() < toolbarHeight) {
                scrollView.scrollTo(0, toolbarHeight);
            }
        }
    }
}
 
Example 3
Source File: ViewPagerTabScrollViewActivity.java    From Android-ObservableScrollView with Apache License 2.0 5 votes vote down vote up
private void propagateToolbarState(boolean isShown) {
    int toolbarHeight = mToolbarView.getHeight();

    // Set scrollY for the fragments that are not created yet
    mPagerAdapter.setScrollY(isShown ? 0 : toolbarHeight);

    // Set scrollY for the active fragments
    for (int i = 0; i < mPagerAdapter.getCount(); i++) {
        // Skip current item
        if (i == mPager.getCurrentItem()) {
            continue;
        }

        // Skip destroyed or not created item
        Fragment f = mPagerAdapter.getItemAt(i);
        if (f == null) {
            continue;
        }

        View view = f.getView();
        if (view == null) {
            continue;
        }
        ObservableScrollView scrollView = (ObservableScrollView) view.findViewById(R.id.scroll);
        if (isShown) {
            // Scroll up
            if (0 < scrollView.getCurrentScrollY()) {
                scrollView.scrollTo(0, 0);
            }
        } else {
            // Scroll down (to hide padding)
            if (scrollView.getCurrentScrollY() < toolbarHeight) {
                scrollView.scrollTo(0, toolbarHeight);
            }
        }
    }
}