Nested RecyclerView in ViewHolder breaks Collapsing Toolbar Layout

后端 未结 3 1088
清歌不尽
清歌不尽 2021-01-04 11:50

I have a vertical RecyclerView hosted in a CoordinatorLayout featuring a collapsing toolbar layout. The ViewHolder for this RecyclerView contains yet another RecyclerView wi

相关标签:
3条回答
  • 2021-01-04 12:00

    So while the above is still true, I found a workaround.

    The workaround involves wrapping the ViewHolder RecyclerView in a RelativeLayout, and overlaying a transparent clickable view over it. In my case, I used a TextView.

    Now while fixes the scrolling, there's still the issue of passing clicks to the right ViewHolder in the ViewHolderRecyclerView. To work around this second setback, I extended the GestureDetector.SimpleOnGestureListener class to contain a recyclerView. Then, I set a OnTouchListener on the wrapperTextView which then forwards the MotionEvent to the GestureDetector.SimpleOnGestureListener subclass.

    The subclass finally interprets the motion event and passes it to the inner RecyclerView, which in turn from the coordinates of the click, figures out the child view clicked and calls performClick() on the child.

    0 讨论(0)
  • 2021-01-04 12:07
    mRecyclerView.setNestedScrollingEnabled(false);
    
    0 讨论(0)
  • 2021-01-04 12:10

    I had the same issue with RecyclerView and CollapsingToolbarLayout, where the RecyclerView was inside a NestedScrollView child layout.

    For me the solution was to set programmatically:

    mRecyclerView.setNestedScrollingEnabled(false);
    

    Note: I tried setting this on the RecyclerView in XML but it did not work?

    android:nestedScrollingEnabled="false"
    

    Another trick to make the CollapsingToolbarLayout scroll is to set a 1000dp min height value to the child of the NestedScrollView

    android:minHeight="1000dp"
    

    why 1000dp? SupportDesignDemos example here: https://github.com/android/platform_development/blob/master/samples/SupportDesignDemos/res/layout/include_appbar_scrollview.xml

    Layout:

    <android.support.design.widget.CoordinatorLayout>
        <android.support.design.widget.AppBarLayout>
            <android.support.design.widget.CollapsingToolbarLayout >
    
                <ImageView/>
                <android.support.v7.widget.Toolbar/>
    
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
        <android.support.v4.widget.NestedScrollView
             app:layout_behavior="@string/appbar_scrolling_view_behavior">
    
            <LinearLayout android:minHeight="1000dp">
    
                <android.support.v7.widget.RecyclerView 
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"
                 />
    
            </LinearLayout>
    
        </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
    
    0 讨论(0)
提交回复
热议问题