roughike / BottomBar

(Deprecated) A custom view component that mimics the new Material Design Bottom Navigation pattern.
Apache License 2.0
8.42k stars 1.5k forks source link

How does it work with viewpager? #5

Closed tinybright closed 8 years ago

roughike commented 8 years ago

It doesn't at this time. I'll look into it and see if it should / can be done.

It seems that this is not meant to be an indicator for ViewPager though:

Using swipe gestures on the content area does not navigate between views. Avoid using lateral motion to transition between views.

roughike commented 8 years ago

I won't make this a ViewPager indicator for now.

What you want can easily be implemented (but the guidelines discourage doing it) by adding OnPageChangeListener to your ViewPager and selecting tabs manually:

ViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
    @Override
    public void onPageSelected(int position) {
        // select a new tab and animate the selection.
        bottomBar.selectTabAtPosition(position, true);
    }
});
gvete commented 8 years ago

Avoid recursion by adding condition check.

mViewer.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                // select a new tab and animate the selection.
                 if(position != mBottomBar.getCurrentTabPosition())
                mBottomBar.selectTabAtPosition(position, true);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });