RecyclerView inside SwipeRefreshLayout inside NestedScrollViewLayout cannot scroll

I have activity with a crumbling toolbar and a nested scroll view using FrameLayout , in which I put fragments. I originally put in it a FragmentA with CardView .

It works great. When I click the button, although I am replacing this FragmentB with another one containing the RecyclerView .

When I add FragmentB , I cannot scroll to the bottom of the list.

This video shows the problem: VIDEO LINK

Host activity layout:

 <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="340dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp"> ......... ...... </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="fill_vertical" android:fillViewport="true" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <!-- the layout which will be the content of the activity (which will be hosted inside the drawer (NOT the list of the drawer)) --> <FrameLayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" > </FrameLayout> </android.support.v4.widget.NestedScrollView> 

Layout FragmentB:

 <android.support.v4.widget.SwipeRefreshLayout android:id="@+id/contentView" android:layout_width="match_parent" android:layout_height="wrap_content" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android" app:layout_behavior="@string/appbar_scrolling_view_behavior"> <android.support.v7.widget.RecyclerView android:id="@+id/rv_users" app:layout_behavior="@string/appbar_scrolling_view_behavior" android:layout_width="match_parent" android:layout_height="wrap_content" /> <include layout="@layout/view_progress" /> <include layout="@layout/view_retry" /> <!--</LinearLayout>--> </android.support.v4.widget.SwipeRefreshLayout> 
+7
android android-fragments android-recyclerview
source share
4 answers

You put the RecyclerView inside the NestedScrollView .
I think the best solution is to have NestedScrollView or RecyclerView , but not both, because RecyclerView already implements NestedScrollingChild .

I have a similar layout in my application. I did the same - put the RecyclerView in a FrameLayout and then inside the NestedScrollView. It stops working correctly. Without NestedScrollView, everything works fine.

+5
source share

I think this is a scrolling issue, customview extends ListView or RecycleView. this is my angry:

 public class RewriteListView extends ListView { public RewriteListView(Context context) { super(context); } public RewriteListView(Context context, AttributeSet attrs) { super(context, attrs); } public RewriteListView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec); } 

}

to be happy:)

0
source share

Already answered! Two scrollable elements (such as RecycleView and NestedScrollView in your question) cannot work together.

Edit the layout of your activity.

 <ParentLayout> ....... <android.support.design.widget.AppBarLayout android:id="@+id/appbar" android:layout_width="match_parent" android:layout_height="340dp" android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" android:fitsSystemWindows="true"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/collapsing_toolbar" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed|enterAlwaysCollapsed" android:fitsSystemWindows="true" app:contentScrim="?attr/colorPrimary" app:expandedTitleMarginStart="48dp" app:expandedTitleMarginEnd="64dp"> ......... ...... </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> //THIS FRAGMENT WILL BE REPLACED! <FrameLayout android:id="@+id/frame_container" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" > </FrameLayout> ....... </ParentLayout> 

And than by default when you first start this action - replace FrameLayout above - with your first fragment using NestedScrollView (you need to create a new fragment to replace) and after replacing the click on the fragment in your question.

0
source share

Two things:

First of all, you don’t need to embed your fragment container in NestedScrollView if you need to scroll behavior in your activity.

Place the FrameLayout directly in the coordinator layout with the layout_behavior attribute in it, and then just put any fragment with the View scroll (and it doesn't need to have layout_behavior attr).

So in your example you have to fragment:

FragmentA that has a layout with CardView inside NestedScrollView FragmentB with RecyclerView inside SwipeRefreshLayout

Another problem is that you put more than one child in a SwipeRefreshLayout , and as stated in the documentation, it should have only one direct child. a source

0
source share

All Articles