6

我目前正在研究为什么我的一些 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 主要由列表组成。

4

1 回答 1

0

不幸的是,随着 Kotlin 的到来,Google 留下了数据绑定,所以如果你认为它像我一样放慢了速度,那就停止使用它或一起迁移到 Kotlin。对我们来说,尝试处理不断破坏和被抛在后面的东西有点糟糕,但这正是谷歌决定成为的样子。

于 2018-06-19T14:27:41.767 回答