4

I am hiding the Toolbar when scrolled down, the only views left would be the SlidingTabLayout and the ViewPager, just like the behaviour that PlayStore has. But I can see a white empty space after the SlidingTabLayout is moved. How do I eliminate this and let the ViewPager occupies that extra space?

When scrolled up, Toolbar shows When scrolled up, Toolbar shows

When scrolled down, it leaves empty space from SlidingTabLayout When scrolled down, it leaves empty space from SlidingTabLayout

@Override
public void onScrollUp() {
    if (isToolbarHidden()) showToolbar();
}

@Override
public void onScrollDown() {
    if (isToolbarShown()) hideToolbar();
}

private void showToolbar() {
    moveToolbar(0);
    moveTabs(0);
}

private void hideToolbar() {
    moveToolbar(-mToolbar.getHeight());
    moveTabs(-mTabs.getHeight());
}

private void moveTabs(float toTranslationY) {
    if (ViewHelper.getTranslationY(mTabs) == toTranslationY) return;

    ValueAnimator animator = ValueAnimator.ofFloat(ViewHelper
            .getTranslationY(mTabs), toTranslationY)
            .setDuration(ANIMATE_TIME_MILLIS);

    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float translationY = (float) animation.getAnimatedValue();
            ViewHelper.setTranslationY(mTabs, translationY);
        }
    });
    animator.start();
}
5
  • Have you tried calling ViewPager.requestLayout() when the animation updates?
    – Whitney
    Commented Feb 17, 2015 at 16:25
  • yes i have tried, it doesn't work
    – chip
    Commented Feb 18, 2015 at 1:04
  • Hi, have you been able to solve this issue?
    – jaibatrik
    Commented Mar 3, 2015 at 20:55
  • @jaibatrik here try this mzgreen.github.io/2015/02/28/…
    – chip
    Commented Mar 5, 2015 at 3:35
  • Hi! have you find the answer of this issue?
    – ryosu
    Commented Feb 27, 2020 at 2:57

2 Answers 2

0

set the linear layout where you place your extended toolbar to android:animateLayoutChanges="true"

Other than that you want to set that space the toolbar occupies to GONE somehow in order to kick the animation without flickering, and get the blank space out of the way. I never worked with extended Toolbars but this is what I did with a normal toolbar when I wanted it out of the view completely.

0

Try to use RelativeLayout instead of LinearLayout to contain your toolbar.

1
  • Welcome to stackoverflow. This answer is too small. You can either post this as comment to quesiton Commented Aug 7, 2016 at 6:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.