开发一个需求时,有用到ScrollView嵌套RecyclerView,但是发现RecyclerView只显示了5个条目。最后尝试,找到两种解决方案。
方案一:
嵌套一层RelativeLayout然后添加属性 android:descendantFocusability="blocksDescendants"
<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:descendantFocusability="blocksDescendants"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerOther" android:layout_width="match_parent" android:layout_height="wrap_content" android:overScrollMode="never" /> </RelativeLayout>
方案二:
将你的ScrollView替换成android.support.v4.widget.NestedScrollView,并在java代码中设置recyclerView.setNestedScrollingEnabled(false);