我正在为这两种情况寻找一个实际的例子,什么时候使用?我见过类似的线程,但它们只告诉这个“ 必须立即执行绑定(bind) ”,但是对于必须强制执行绑定(bind)的任何情况,都没有实时示例。所以请如果有人可以用任何例子解释什么时候使用它,什么时候不需要它!
最佳答案
应该使用 executePendingBindings()
的情况是(但可能还有更多):
Every time the binding update could cause a View to change its size and postponing the calculation in the next frame could cause the measurement to read wrong values.
如果是
RecyclerView
,如果发生这种情况:viewType
不同大小的s(不同的XML)RecyclerView
将在 onBindViewHolder
之后测量行大小已完成。如果根据您在此方法中设置的数据,行高发生变化,如果您不调用 executePendingBindings()
,则测量无法考虑新内容占用的额外或减少空间。 .强制绑定(bind)同步更新数据,而不是在下一帧中,可以防止错误的行大小测量(以及可能丢失的内容)
关于android - 何时使用 executePendingBindings() 何时不需要?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58678913/