是否应该对RecyclerView项目视图使用数据绑定?

问题描述 投票:6回答:1

我正在研究为什么我的一些RecyclerViews表现不佳。当需要绘制视图的整个内容时,UI尤其滞后。 使用systrace我遇到了一个大框架,其中RecyclerView布局其视图:

enter image description here

如您所见,重复绘制相同的视图。在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的视图使用谷歌的data binding与可观察的值。 更新TextView的意思我不使用textView.setText(titleTxt)title.set(titleTxt)其中title将是ObservableField<String>类型。 所以我显然不是在调用notifyItemChanged,而只是更新绑定到布局的对象上的可观察字段。

在这种情况下使用数据绑定在性能方面是错误的吗?如果是这样,那么数据绑定的意义何在?移动UI主要由列表组成。

android performance android-recyclerview android-databinding systrace
1个回答
0
投票

不幸的是,随着Kotlin的到来,谷歌留下数据绑定,所以如果你认为它会像我一样放慢速度,只需停止使用它或者一起移动到Kotlin。有点糟透了我们尝试使用不断破坏和落后的东西,但这正是谷歌决定成为的。

© www.soinside.com 2019 - 2024. All rights reserved.