In my activity I have a BottomNavigationView and a RecyclerView, and what I want to do is to hide the BottomNavigationView when I scroll the view, I'm using this code:
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
BottomNavigationView navigationView = requireActivity().findViewById(R.id.bottom_navigation_view);
if (recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING && dy > 0){
navigationView.animate()
.translationY(navigationView.getHeight());
}
else if(recyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING && dy < 0)
navigationView.animate()
.translationY(0);
}
});
This works fine except for the fact that it still shows the bounds of the view, so after hiding the BottomNavigationView I get an empty rectangle. What is the best way to make the height of the view follow the translation?
I don't see how your "hiding"
BottomNavigationViewbut if your using
BottomNavigationView.setVisibility(View.INVISIBLE);which hides the view but keeps its width and height.
it needs to be
BottomNavigationView.setVisibility(View.GONE);which hides the view and makes the width = 0 and height = 0