隐藏BottomNavigationView滚动查看 [英] Hiding BottomNavigationView on scroll

查看:294
本文介绍了隐藏BottomNavigationView滚动查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现材质设计的底部导航栏 https://material.io/guidelines/components/bottom-navigation.html

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)

推荐答案

这对我有用.

我在gridview中使用了向上滑动"和向下滑动"动画.当网格向上滚动然后隐藏bottomNavBar,向下滚动则显示bottomNavBar.而已.

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;
}

这篇关于隐藏BottomNavigationView滚动查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆