【问题标题】:In which cases does the DataBinding.executePendingBindings should be used and when should be avoided?在哪些情况下应该使用 DataBinding.executePendingBindings,什么时候应该避免?
【发布时间】:2019-08-05 12:53:15
【问题描述】:

我从不同来源了解到executePendingBindings() 方法,但无法找到确切的答案,何时应该使用以及何时应该避免使用。

我能够找到的信息类似于以下内容:executePendingBindings() 立即执行未完成的绑定,而不是等到下一帧被绘制。而且此方法将从 UI 线程执行所有绑定,否则可以从非 UI 线程调用 setVariable() 调用。如果为大量列表中的项目触发executePendingBindings(),则这些调用可能会影响recyclerview's 的性能。 就这样。没有关于它的使用的确切建议。

那么,问题是:在什么情况下应该调用executePendingBindings()?哪个没有?

【问题讨论】:

    标签: java android kotlin data-binding android-databinding


    【解决方案1】:

    抱歉,我最初理解了这个问题。

    我猜executePendingBindings() 完全按照它所说的那样立即执行,而无需等待下一帧。

    我认为您应该在每次使用数据绑定时都使用executePendingBindings()

    话虽如此,如果您不使用executePendingBindings(),您的视图可能不会立即更新,因为它只会在下一帧渲染时执行绑定。当您在较旧或较慢的设备上运行时,您可能只会注意到副作用。

    如果您想了解回收站视图的呈现方式,我认为this article 是必读的。

    这里的另一个好读物slow rendering

    【讨论】:

    • 这不能回答问题。我的问题只是关于 executePendingBindings() 方法及其用例。
    猜你喜欢
    • 2018-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2016-06-30
    • 1970-01-01
    • 1970-01-01
    • 2016-02-19
    相关资源
    最近更新 更多