You Qi You Qi - 1 month ago 25x
Android Question

Scroll not working for multiple RecyclerView in BottomSheet

I implemented

using the
approach. I have a
in the
. The
is hosting 2 pages, each inflates a
. The first(Coffee tab)
scrolls fine. The problem I'm having now is that for the 2nd(Milk tab) the scroll is not working. Any idea how can I fix this? Thanks!

You can test out with the demo project I created here:`

enter image description here


When trying to look for the problem on StackOverflow I found this thread. It depicts about the bug (at least that is how I look at it), that BottomSheetBehaviour works only for the first scrollable child it finds. It also proposes the usage of different CoordinatorLayout.Behavior proposed and published here.

However, your case is a bit different. BottomSheetDialogFragment is used. And this is where the provided solution does not work. However I managed to oveercome this problem. Published repository, where your project was modified to be working. It uses the ViewPagerBottomSheetBehavior from the library mentioned earlier.

Basically, the following changes were made:

  1. StatisticFragment extends ViewPagerBottomSheetDialogFragment and not BottomSheetDialogFragment
  2. The onCreateDialog function in StatisticsFragment is changed:

    public Dialog onCreateDialog(Bundle savedInstanceState) {
        ViewPagerBottomSheetDialog dialog = (ViewPagerBottomSheetDialog) super.onCreateDialog(savedInstanceState);
        View rootView = View.inflate(getContext(), R.layout.sheet_main, null);
        viewPager = (ViewPager) rootView.findViewById(;
        tabLayout = (TabLayout) rootView.findViewById(;
        mBehavior = ViewPagerBottomSheetBehavior.from((View) rootView.getParent());
        if (viewPager != null && tabLayout != null) {
        return dialog;
  3. The following function is invoked on the ViewPager:


And that is all. The project works.

The following is done behind the scenes:

BottomSheetDialogFragment has only one method:

public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new BottomSheetDialog(getContext(), getTheme());

There BottomSheetDialog is returned. However, it has staticly defined behaviour set to BottomSheetBehavior. What was needed was to override ViewPagerBottomSheetDialogFragment to return ViewPagerBottomSheetDialog where it's CoordinatorLayout.Behavior is set to ViewPagerBottomSheetBehavior. Also the custom BottomSheet was needed to be overriden to accustom to ViewPagerBottomSheetBehavior.