转载https://blog.csdn.net/qq_38619138/article/details/92839539
当recyclerView数据较少或取数据时 滑动不下来 appBar不能顺利展开
解决办法是把recyclerView的高度设置为match_parent 我之前用的是wrap_content
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_account_more_info"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="true"
android:scrollbars="none"
app:layout_anchor="@id/appbar_bg"
app:layout_anchorGravity="bottom"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</android.support.v7.widget.RecyclerView>
问题二:当RecycleView嵌套多个RecycleView时,与AppBarLayout产生的滑动问题
recycleview抢占焦点,从而AppBarLayout滑动不上去
解决办法:为最子层得RecyclerView增加一句setNestedScrollingEnabled(false)
CoordinatorLayout实现了NestedScrollingParent,纵向RecyclerView是CoordinatorLayout的子View,RecyclerView的滑动能通知到CoordinatorLayout,继而由CoordinatorLayout协调让CollapsingToolbarLayout发生折叠。
上面出bug的原因也能理解了,横向RecyclerView的父View是纵向RecyclerView,而RecyclerView只实现了NestedScrollingChild,无法像CoordinatorLayout一样响应。所以要关闭横向RecyclerView的嵌套滑动功能,让横向RecyclerView如同其他嵌入纵向RecyclerView的view一样,触发折叠。