Android 如何使用clipToPadding=false向RecyclerView添加额外空间以防止过早回收

Android 如何使用clipToPadding=false向RecyclerView添加额外空间以防止过早回收,android,android-recyclerview,Android,Android Recyclerview,我的布局如下: <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:clipToPadding="false"> <android.support.v7.widget.RecyclerView android:layout_

我的布局如下:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@+id/searchView"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:scrollbars="vertical"
        app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>

    <SearchView
        android:id="@+id/searchView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
</RelativeLayout>


此方法应该可以帮助您
setItemViewCacheSize(int size)
。它设置将屏幕外视图添加到可能共享的循环视图池之前要保留的视图数。你可以找到更多关于它的信息。

实际上它不起作用;医生说了我想读的内容,但实际上视图消失了。假设我将大小设置为1,当第一个视图超出RecyclerView的区域时,它会消失,可能它没有被回收,但肯定不再可见……真的很奇怪。对你来说,放一个gif或者一个链接到发生这种事情的视频会是一个大问题吗?是否可能有其他视图覆盖了recycler的顶部?您也可以通过放置
recyclerView.getRecycledViewPool().setMaxRecycledViews(键入我的项目,0)来打开回收其中TYPE_MY_ITEM是您不希望回收的视图类型。通过这种方法,您可以测试是回收有问题还是其他问题。我添加了一个gif,结果与使用1、2或nIt调用的setItemViewCacheSize(size)相同,看起来回收器正在删除它们。尝试放置
RecycleView.getRecycledViewPool().setMaxRecycledViews(类型_‌​我的第20项)到20或其他大数字。问题是,你们的视图很小,屏幕上有很多视图,所以它们很早就开始回收。我希望这会有所帮助,因为我没有想法:)。