关于ScrollView嵌套RecyclerView时RecyclerView不显示的问题

  在新版本中需求变更导致布局需要变化,RecyclerView外需要一层ScrollView来处理滑动。发布前夕发现在API 23 & 24上RecyclerView显示不完整。

  光速冷静下来,马上去stackoverflow翻了一下,有人说ScrollView加上 android:fillViewport="true" ,但是我加上并没有解决问题。后来在RecyclerView外面加了一层RelativeLayout,问题解决。如果你在API 23 & 24上也遇到这个问题,可以参考一下。

<android.support.v4.widget.NestedScrollView
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       >

       <!-- DEV NOTE: Outer wrapper relative layout is added intentionally to address issue
                that only happens on Marshmallow & Nougat devices (API 23 & 24).
                On marshmallow API 23, the "RecyclerView" `layout_height="wrap_content"` does NOT
                occupy the height of all the elements added to it via adapter. The result is cut out
                items that is outside of device viewport when it loads initially.
                Wrapping "RecyclerView" with "RelativeLayout" fixes the issue on Marshmallow devices.
           -->

       <RelativeLayout
           android:layout_width="match_parent"
           android:layout_height="wrap_content">

           <com.jcodecraeer.xrecyclerview.XRecyclerView
               android:id="@+id/rv_fragment_find_tips_list"
               android:layout_width="match_parent"
               android:layout_height="wrap_content" 
               />
       </RelativeLayout>


   </android.support.v4.widget.NestedScrollView>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容