一、在RecyclerView外层套一层RelativeLayout:
这样做为什么?解决RecyclerView展示不全的问题。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
二、禁止RecyclerView的纵向滑动(横向同理):
这样做为什么?解决RecyclerView滑动无惯性问题,解决滑动显示头尾阻尼问题。
recyclerView.setLayoutManager(new LinearLayoutManager(this){
@Override
public boolean canScrollVertically() {
return false;//禁止滑动
}
});
三、禁止RecyclerView的默认聚焦:
这样做为什么?解决RelativeLayout处于非顶部,却在加载后处于页面顶部的问题
recyclerView.setFocusable(false);//关闭默认聚焦
kotlin版的两项配置:
recyclerView.layoutManager = object :LinearLayoutManager(this){
override fun canScrollVertically(): Boolean {
return false
}
}
recyclerView.isFocusable = false