小编Dmi*_*try的帖子

使用 RecyclerView 和 LinearLayoutManager 使用 reverseLayout == true 的奇怪行为(错误?)

当使用带有 LinearLayoutManager 和“reverseLayout”标志设置为 true 的 RecyclerView 时,当通过notifyItemChanged它通知任何项目时,也会调用onBindViewHolder第一个不可见的项目。之后它不会要求onViewRecycled该项目。因此,如果 ViewHolder 在 onBind 中进行某种订阅,它将永远不会被释放,因为不会调用 onRecycle。

这实际上看起来像是LinearLayoutManager. 如果您查看fillLinearLayoutManager中的方法,则有以下代码:

if (!layoutChunkResult.mIgnoreConsumed || layoutState.mScrapList != null || !state.isPreLayout()) {
    layoutState.mAvailable -= layoutChunkResult.mConsumed;
    // we keep a separate remaining space because mAvailable is important for recycling
    remainingSpace -= layoutChunkResult.mConsumed;
}
Run Code Online (Sandbox Code Playgroud)

据我所知,我们迭代子视图,直到我们填满所有需要的空间,换句话说layoutState.mAvailableremainingSpace它们都以像素为单位。如果您进一步layoutChunk查看方法中发生的事情,您将看到这段代码:


// Consume the available space if the view is not removed OR changed
if (params.isItemRemoved() || params.isItemChanged()) {
    result.mIgnoreConsumed = …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview linearlayoutmanager

10
推荐指数
0
解决办法
424
查看次数