Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll behavior in nested RecyclerView with horizontal scroll

I have to create vertical RecyclerView with nested horizontal RecyclerView in every item. Everything is within CoordinatorLayout. When I scroll by tapping outside nested RecyclerView toolbar hides, but when I scroll parent Recycler by tapping on nested one toolbar stays.

Any help would be appreciated.

Here is my xml layouts:

main_activity.xml:

<android.support.design.widget.CoordinatorLayout     ...>  <FrameLayout     android:id="@+id/fragment_frame"     ...     android:fitsSystemWindows="true"     app:layout_behavior="@string/appbar_scrolling_view_behavior"/>  <android.support.design.widget.AppBarLayout     ...     android:fitsSystemWindows="true"     android:id="@+id/appbar_layout">          <include layout="@layout/toolbar"/>  </android.support.design.widget.AppBarLayout> </android.support.design.widget.CoordinatorLayout> 

Here is toolbar.xml :

<android.support.v7.widget.Toolbar     android:id="@+id/main_toolbar"     ...     android:fitsSystemWindows="true"     app:layout_scrollFlags="scroll|enterAlways">      <TextView .../>  </android.support.v7.widget.Toolbar> 

fragment.xml:

<android.support.v7.widget.RecyclerView     ...     android:scrollbars="vertical"     app:layout_behavior="@string/appbar_scrolling_view_behavior"/> 

And recycler_view_item.xml:

<RelativeLayout ...>      <TextView .../>      <!-- fixme(CullyCross) fix bug with hiding toolbar -->     <android.support.v7.widget.RecyclerView         ...         android:scrollbars="horizontal"         app:layout_behavior="@string/appbar_scrolling_view_behavior"         />  </RelativeLayout> 

Thanks,
Anton

like image 408
Anton Shkurenko Avatar asked Sep 11 '15 14:09

Anton Shkurenko


People also ask

What is nested scroll view?

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

Can you display a scrolling list of items in a RecyclerView?

To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .


2 Answers

As requested here is the solution I found good enough so far:

In my case I have a nestedScrollView with 4 RecyclerViews set to scroll horizontally inside. For each of those RecyclerViews I have done this programatically:

restaurantsRecylerView.setHasFixedSize(true);  restaurantsRecylerView.setNestedScrollingEnabled(false); 

You probably don't want the fixedSize, not sure if it will make any difference, my list is always 25 so I can use that for performance. After having done this I can scroll without issues even when I touch on the recyclerViews

Hope it helps

like image 119
Lancelot Avatar answered Sep 28 '22 03:09

Lancelot


Try with RecyclerView inside android.support.v4.widget.NestedScrollView.

<android.support.v4.widget.NestedScrollView         android:id="@+id/nScrollView"         android:layout_width="match_parent"         android:layout_height="match_parent">  <!-- Set other views of your Layout -->  </android.support.v4.widget.NestedScrollView> 

Also try with different layout_scrollFlags in Toolbar and

RecylerView.setNestedScrollingEnabled(false); // set it true or false as per requirement 
like image 25
Priyank Patel Avatar answered Sep 28 '22 05:09

Priyank Patel