javaandroidlistviewandroid-recyclerviewslidingpanelayout

SlidingPaneLayout items in RecyclerView


I'm populating a RecyclerView with several SlidingPaneLayout items, as to achieve a 'swipe to delete' functionality (basically, dragging an item to the right reveals a DELETE button)

Problem: When I drag an item to the right, it seems like the RecyclerView also intercepts my touches, and if my drag is somewhat diagonal (or not too horizontal) - the RecyclerView starts scrolling and the SlidingPaneLayout cancels the closing/opening of the pane

I've tried adding a touch listener to each SlidingPaneLayout that prevents the RecyclerView from intercepting the touches once ACTION_DOWN is performed on the SlidingPaneLayout, but that's not good as it blocks scrolling right away

ideas?


Solution

  • The solution:

    Prevent the RecyclerView from intercepting touch events given the following condition:

    10% < sliding pane offset < 90%

    i.e

    ViewParent parent = ...; // Should be the RecyclerView
    parent.requestDisallowInterceptTouchEvent(slideOffset > 0.1 && slideOffset < 0.9)