首先我的代码运行
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvPrices"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintTop_toTopOf="parent"
tools:itemCount="3"
tools:listitem="@layout/business_item_fire_job_price_des" />
在回收器视图 xml 中设置布局管理器
问题是,当项目添加到适配器时,我可以看到它调用了bindData的日志,但在某些情况下,recyclerview消失了,任何人都可以解释为什么吗?
似乎当 UI 刷新有点滞后时就会出现问题(在 android studio miror 设备中,问题发生得更频繁)
我尝试将布局管理器更改为垂直,它工作正常,但我希望回收器视图水平布局
我现在有一个解决方法 在代码中设置布局管理器,如下所示: 将 isMeasurementCacheEnabled 设置为 false 解决问题 有人能告诉为什么吗? rvPrices.layoutManager = LinearLayoutManager(context,LinearLayoutManager.HORIZONTAL,false).apply { isMeasurementCacheEnabled = false }