Search code examples
androidandroid-coordinatorlayout

Bottom Sheet and ListView


When I scroll down in the ListView, BottomSheep starts to close. Is there any way to do this so that the interaction of closure happens only when you touch the Bottom Sheet Peek (with an example). Also, an example is interested in where Bottom Sheet is blocked by touching a finger, that is, opening and closing is done by code.

enter image description here


Solution

  • That's because nested scroll events are being passed up to the bottom sheet. What you need to do is disable this behaviour by setting isNestedScrollingEnabled to false (Kotlin) or setNestedScrollingEnabled(false) (Java).

    This has to be set in a direct child of the Bottom Sheet but this child needs to support nested scrolling. So, wrap the ListView inside a NestedScrollView, SwipeRefreshLayout or anything that supports nested scrolling and disable nested scrolling as below

    swipeRefreshLayout?.isNestedScrollingEnabled = false
    

    or in java

    swipeRefreshLayout.setNestedScrollingEnabled(false);