美文网首页
RecyclerView使用注意事项

RecyclerView使用注意事项

作者: pandaneko | 来源:发表于2019-12-28 17:11 被阅读0次

1,不显示内容。首先检查是否漏了

setLayoutManager(linearLayoutManager)

这个是低级错误。没问题的话检查

adapter.notifyDataSetChanged()

之前是否设置了list内容,注意设置list数据时不能用=号赋值,要先clear()再addAll。
2,ScrollView嵌套recyclerview时,初始默认焦点在recyclerview上。给ScrollView的子元素(例如LinearLayout)增加

android:descendantFocusability="blocksDescendants"

属性可以解决这个问题
3,RecyclerView单独用且自适应高度,计算高度有时会有问题。解决办法是嵌套一个RelativeLayout:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
 
        <android.support.v7.widget.RecyclerView... />

</RelativeLayout>

相关文章

网友评论

      本文标题:RecyclerView使用注意事项

      本文链接:https://www.haomeiwen.com/subject/msbsoctx.html