When dragging an object from visible space to recyclerview to nestedscrollview - nested scrollView does not scroll

I have a design where there are two elements that are static and recyclerview with draggable elements. Both types of views are wrapped in LinearLayout. LinearLayout wrapped NestedScrollView.

XML explanation:

<NestScrollView> <LinearLayout> <View></View> <View></View> <RecyclerView></RecyclerView> </LinearLayout> </NestScrollView> 

Pic Description:

enter image description here

Implementing drag and drop elements taken from this tutorial: https://medium.com/@ipaulpro/drag-and-swipe-with-recyclerview-6a6f0c422efd#.yc7me2ikf

The problem is that the RecyclerView does not scroll when I pull its children out of the screen. (However, if I don't have a NestedScrollView parent, the RecyclerView works as expected.)

I searched for every problem related to this, but I did not find any solution.

+6
source share
3 answers

Putting a recyclerView inside a NestedScrollView not good practice. I recommend that you use other views as recyclerView elements. I am sure this will fix your problem, as you said, "However, if I do not have a NestedScrollView parent, RecyclerView works as expected."

0
source

Make NestedScrollView and RecyclerView pleasant together by adding android:fillViewport="true" to recycler

When you start dragging your item or when you reach the edge of the screen, you can also disable the recycler nested behavior with mRecyclerView.setNestedScrollingEnabled(false) . This will cause the nested view to scroll so that the user continues to use recyclerview.

Once you're done, set the nested scroll to true again.

Alternatively, you will need to look at the delegation that receives touch events, as I set out for another question here . For your sample, this could be simple:

  • When dragging, a call to nestedScrollView.requestDisallowInterceptTouchEvent(true); begins nestedScrollView.requestDisallowInterceptTouchEvent(true);
  • When drag ends requestDisallowInterceptTouchEvent(false) to re-view scrollview

If requestDisallowInterceptTouchEvent does not work, you can subclass NestedScrollView and override onInterceptTouchEvent as in my related answer

0
source

Go with something like:

  <FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v4.widget.NestedScrollView android:id="@+id/view_noRecord" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <TextView android:id="@+id/tv_no_record" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_marginBottom="@dimen/_20sdp" android:gravity="center_horizontal" android:padding="@dimen/_10sdp" android:text="@string/no_data_found" android:visibility="gone" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </android.support.v4.widget.NestedScrollView> <android.support.v7.widget.RecyclerView android:id="@+id/common_recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:fadeScrollbars="true" android:scrollbars="vertical" android:visibility="gone" app:layout_behavior="@string/appbar_scrolling_view_behavior" /> </FrameLayout> 

Or try putting content from your layout as the title of your RecyclerView

 <LinearLayout> <View></View> <View></View> </LinearLayout> 
-one
source

Source: https://habr.com/ru/post/1015584/


All Articles