天天看点

ScrollView 嵌套 LinearLayout 嵌套 RecyclerView 出现 item 显示不全的问题

参考:

1. https://blog.csdn.net/lyh1299259684/article/details/78494655

2. https://blog.csdn.net/a568478312/article/details/79881540

碰到了这个问题, 找了一下发现网上有解决方案, 顺着解决了, 这里记录一下.

我的业务场景是这样嵌套的.

ScrollView 嵌套 LinearLayout 嵌套 RecyclerView 出现 item 显示不全的问题

这样导致了item显示不全的bug. 从参考的第二个链接可以知道产生这个问题的原理.

但是实际解决问题我是在参考1中的链接找的. 具体就是使用

<android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">
       <LinearLayout
             android:orientation="vertical"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">
            <RecyclerView />
       </LinearLayout>
</android.support.v4.widget.NestedScrollView>
           

然后调用 recyclerView.setNestedScrollingEnabled(false); 这个方法即可解决. 棒棒哒