我最近将支持库recyclerview-v7:23.1.1更新为recyclerview-v7:25.1.0。
我的布局包含2个RecyclerView,屏幕上分为50%。XML代码如下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none"/>
<android.support.v4.widget.Space
android:layout_width="@dimen/two_dp"
android:layout_height="match_parent"
android:background="@color/dark_gray"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:scrollbars="none"/>
</LinearLayout>
现在, onBindViewHolder 会为所有列表项调用,而不仅仅是可见项。 这是在更新到 support library 25.1.0 后开始出现的。
如果去掉权重,则可以正常工作,但需要并排放置两个recylcerviews。
如何告诉recyclerview回收视图而不是加载全部?
更新:它在Marshmallow及以上设备上运行良好。该问题存在于Lollipop或更早版本中。 您可以在此处找到演示项目: https://bitbucket.org/aniketit/recyclerviewtest