小编Ani*_*nde的帖子

当使用权重在LinearLayout内部时,Recyclerview onBindViewHolder调用所有项目

我最近从支持库recyclerview-v7:23.1.1更新到recyclerview-v7:25.1.0.

我的布局包含2个在屏幕上分割50%的recylerviews.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>
Run Code Online (Sandbox Code Playgroud)

现在为所有列表项而不是仅显示可见项调用onBindViewHolder. 这在更新后开始发生,以支持库25.1.0.

如果移除重量,它可以正常工作,但需要并排显示2个重定向视图.

如何告诉recyclerview回收视图而不是加载所有视图?

更新:它适用于棉花糖及以上设备.该问题出现在棒棒糖或以下.您可以在这里找到一个演示项目: https ://bitbucket.org/aniketit/recyclerviewtest

android android-support-library android-recyclerview

17
推荐指数
1
解决办法
2782
查看次数