BottomNavigationView hides when scrolling up instead of down

我与影子孤独终老i 提交于 2019-12-06 13:26:05

This release of BottomNavigationView is missing scrolling behavior to work out of the box as specified in the guidelines.

I wrote an article on what's missing and how you can fix it. This includes implementing scrolling behavior of the BottomNavigationView in CoordinatorLayout.

A simple solution is to just add an offset listener to appbarlayout. Works perfectly for me.

So something like this:

((AppBarLayout)toolbar.getParent()).addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
    @Override
    public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
        mNavigationBar.setTranslationY(verticalOffset*-1);
    }
});
kassim

My solution was to replace the FrameLayout with a NestedCoordinatorLayout from here https://stackoverflow.com/a/37660246/2233621 and then add the BottomNavigationBehavior from Nikola's blog post https://medium.com/@nullthemall/bottomnavigationview-missing-pearls-eaa950f9ad4e#.p1i01wwui that way your bottom navigation behaviour can listen for nested scrolling of the fragment inside the NestedCoordinatorLayout

I believe you could use another view that implements NestedScrollParent + NestedScrollChild for the same behaviour.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!