1

I am implementing the bottom navigation bar of the material design https://material.io/guidelines/components/bottom-navigation.html

It suggests that while scrolling down , we should hide the bar , and show it while scrolling up.

I am a little lost in how to go about this. Should I have to manually do that , or there is some functionality built in inside the view that would do it.

Do I have some behaviour for this ? (as the bottomnavigation is a child of coord layout)

Muhammad Ahmed AbuTalib
  • 4,080
  • 4
  • 36
  • 59
  • 1
    You have to write your custom [Behavior](https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.Behavior.html). – azizbekian Mar 31 '17 at 13:57
  • shoot . that appears painful – Muhammad Ahmed AbuTalib Mar 31 '17 at 14:11
  • Possible duplicate of [Hide/Show bottomNavigationView on Scroll](https://stackoverflow.com/questions/44777869/hide-show-bottomnavigationview-on-scroll) – sunadorer Aug 20 '18 at 10:00
  • @MuhammadAhmedAbuTalib Old question which now finally has a much simpler answer thanks to the latest Support Library update / AndroidX release. Check out my answer at https://stackoverflow.com/a/51917114/414581 – sunadorer Aug 20 '18 at 10:02

1 Answers1

0

This is work for me.

I have used "slide up" and "slide down" animation for my gridview. when grid scroll upward then hide bottomNavBar and when scroll downward then show bottomNavBar. that's it.

myGridView.setOnTouchListener(this);

int y, initialY, scrollingY, scrolledY;
boolean isVisible = true;

@Override
public boolean onTouch(View view, MotionEvent motionEvent) {

    y = (int) motionEvent.getRawY();

    switch (motionEvent.getAction()) {

        case MotionEvent.ACTION_DOWN:
            initialY = (int) motionEvent.getRawY();
            Log.e("Down===", initialY+"");
            break;

        case MotionEvent.ACTION_MOVE:
            scrollingY = (int) motionEvent.getRawY();
            Log.e("Move===", scrollingY+"");

            switch (view.getId()) {

                case R.id.exploreGridMain:
                    if(isVisible && initialY > scrolledY) {
                        bottomNavigationView.startAnimation(slideDown);
                        slideDown.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                bottomNavigationView.setVisibility(View.GONE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        isVisible = false;
                    } else if(!isVisible && initialY < scrolledY){
                        bottomNavigationView.startAnimation(slideUp);
                        slideUp.setAnimationListener(new Animation.AnimationListener() {
                            @Override
                            public void onAnimationStart(Animation animation) {

                            }

                            @Override
                            public void onAnimationEnd(Animation animation) {
                                bottomNavigationView.setVisibility(View.VISIBLE);
                            }

                            @Override
                            public void onAnimationRepeat(Animation animation) {

                            }
                        });
                        isVisible = true;
                    }
                    break;
            }
            scrolledY = scrollingY;
            break;

        case MotionEvent.ACTION_UP:
            Log.e("Up===", scrolledY+"-"+y);

            break;
    }
    return false;
}