Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Scrolling in child Recyclerview android

Tags:

I have a layout consists of a Parent RecyclerView with a sub Recyclerview in it

i know that it is not good to put a list inside another list but i have to so that i can use the sub list features like swiping and drag and drop

My issue is that the child Recyclerview gain focus and stops the parent from scrolling if the touch point was on it simply i want if the touch was vertically on the child Recyclerview the parent scrolls up and down and if the touch was horizontal or a click then the child Recyclerview list item swipes left and right. Any help to achieve this?

like image 548
Abdullah Adel Essa Avatar asked May 13 '15 18:05

Abdullah Adel Essa


People also ask

How to prevent scroll on RecyclerView?

Basically, you need to add android:overScrollMode=“never” line to your RecyclerView.

How do I stop refreshing RecyclerView data scroll to top position android?

Make a setDataList method in your adapter class. And set your updated list to adapter list. And then every time of calling API set that list to setDataList and call adapter. notifyDataSetChanged() method of your adapter class.

How can show all items in RecyclerView without scrolling?

In RecyclerView use android:nestedSrollingEnabled="false" and use NestedScrollView as a parent Scroll View. This was the only answer that worked for me - I had a ScrollView wrapping two RecyclerViews.

How do I stop NestedScrollView scrolling?

setnestedscrollingenabled set it to false. try this one add property in recyclerview android:descendantFocusability="blocksDescendants" .


1 Answers

I finally found a solution.

Create Custom LinearLayoutManager

public class CustomLinearLayoutManager extends LinearLayoutManager {
public CustomLinearLayoutManager(Context context, int orientation, boolean reverseLayout) {
    super(context, orientation, reverseLayout);

}

// it will always pass false to RecyclerView when calling "canScrollVertically()" method.
@Override
public boolean canScrollVertically() {
    return false;
}
}

Then instantiate it like this for vertical scrolling

CustomLinearLayoutManager customLayoutManager = new CustomLinearLayoutManager(getActivity(),LinearLayoutManager.VERTICAL,false);

Finally set the custom layout as layout manager of recycler view

recyclerView.setLayoutManager(customLayoutManager);
like image 91
Behzad Bahmanyar Avatar answered Sep 21 '22 00:09

Behzad Bahmanyar