我目前正在研究为什么我的一些 RecyclerViews 表现不佳。UI 滞后,尤其是在需要绘制视图的全部内容时。
使用 systrace 我遇到了一个大框架,RecyclerView 在其中布局其视图:
如您所见,重复绘制相同的视图。在 systrace 中,我在 RecyclerView 框架上找到了以下描述:
OnLayout has been called by the View system. If this shows up too many times in Systrace, make sure the children of RecyclerView do not update themselves directly. This will cause a full re-layout but when it happens via the Adapter notifyItemChanged, RecyclerView can avoid full layout calculation.
我的 RecyclerView 的视图正在使用带有可观察值的谷歌数据绑定。
意思是更新我不使用的 TextViewtextView.setText(titleTxt)
但title.set(titleTxt)
wheretitle
将是 type ObservableField<String>
。
所以显然我没有调用notifyItemChanged
,而只是更新绑定到布局的对象上的可观察字段。
在这种情况下使用数据绑定是错误的吗?如果是这样,那么数据绑定的意义何在?移动 UI 主要由列表组成。