ScrollView嵌套RecyclerView显示不全

xiaoxiao2021-02-28  101

项目有个需求要在ScrollView中嵌套RecyclerView,布局如下:

<ScrollView android:layout_width="match_parent" android:layout_height="match_parent"> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="其他布局" android:layout_width="match_parent" android:layout_height="wrap_content" /> <android.support.v7.widget.RecyclerView android:id="@+id/rv_test_in_scroll_view" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </ScrollView>

这时候内层RecyclerView是可以滚动的,通过代码设置RecyclerView不可滚动:

recyclerView.setNestedScrollingEnabled(false);

结果这时候列表显示不全了。

尝试过以下解决方案:

例如:ScrollView 设置属性android:fillViewport="true"

例如:RecyclerView外套一层LinearLayout或RelativeLayout

例如:改里外控件的layout_height属性

反正都没生效,难道剩下的就只有纯JAVA的方式了吗?

最后把 ScrollView 改成 NestedScrollView,问题解决。。。

转载请注明原文地址: https://www.6miu.com/read-33416.html

最新回复(0)