Recently,I was working on the Chestream Android app and as it turns out, AndroidSlidingUpPanel doesn’t play well with scrolling contents and since we were using RecyclerView inside SlidingPanelLayout, there were some conflicts between the srcolling intercepting of slidingpanel and recyclerview.The problem was that when scrolling inside the recyclerview,it did not scroll instead the panel starts sliding.However for some reason,if scrolled very slowly recyclerview did started scrolling but it was bad user experience.The problem is justified as panel is supposed to slide if it is dragged.There is also a method setDragView in SlidingPanelLayout by which we can restrict the views from where only the panel can be dragged but unfortunately that doesn’t seem to work and even if it works,it isn’t the perfect solution to the problem as then the user wouldn’t be able to drag the panel from the whole recyclerview.
The ideal solution to this should be that the user will be able to scroll the recyclerview as long as it is scrollable and when the top item of recyclerview is reached,the panel should start sliding.We will see how to implement such functionality with AndroidSlidingUpPanel.This should work on ScrollViews and ListViews also.
On first look,it would seem to override the onInterceptTouchEvent in SlidingUpPanelLayout to implement your custom implementation (And what most of the stackoverflow answers relating to this suggest) but unfortunately this wouldn’t work in our case as once the child view’s onTouchEvent returns true,onInterceptTouchEvent would no longer be called.So our first step would be to remove onInterceptTouchEvent method completely.
Add these variables to SlidingUpPanelLayout.java
Next up is to give SlidingUpPanelLayout the reference to our RecyclerView.
Add this method to SlidingUpPanelLayout.java-
Next step is to determine if our RecyclerView is still scrolling or has reached the top item and its time to hand over scrolling to SlidingPanelLayout. It took me some time to find it but LayoutManager of RecyclerView has a direct method to get the position of the first visible item on the screen. Similarly,ListView and ScrollView also has such methods to get the scrolling position.
Next modify the onTouchEvent of SlidingUpPanelLayout to the following-
Add the isScrollingViewUnder as follows (same as the isDrageViewUnder method)-
And then finally add the following dispatchTouchEvent method to identify if we want to handle the touch event.
We want to be able to handle the case where a child begins handling a touch event, but then the parent takes over. If we rely on onInterceptTouchEvent, we lose control of the touch as soon as the child handles the event.
(see http://stackoverflow.com/a/22490810/3316330 for more details)
That’s it! We just need to set our scrollingView to the SlidingUpPanelLayout.
Add this line to give the sliding layout the reference to our RecyclerView.
This should solve the scrolling problem when using RecyclerView with AndoridSlidingUpPanel.
As of version 3.1.0 released on 19 July,AndroidSlidingUpPanel has added
scrollableView to support nested scrolling in children
but only scrollview and listview are supported for now.
https://github.com/umano/AndroidSlidingUpPanel/pull/503.