recyclerView刷新图片闪烁

475 阅读1分钟

禁用默认的 ItemAnimator: 在适配器设置时,尝试禁用默认的 ItemAnimator,以避免默认的动画效果。

recyclerView.setItemAnimator(null);

另:适配器刷新单个item时,整个页面会闪烁的问题:

原因:因为我的adapter itemview中有自定义的PostImageLayout和ShowAllTextView,高度是wrap_content,父容器是ConstraintLayout,导致notifyItemChanged时,也会导致整个页面严重闪烁。 解决办法:对自定义设置固定高度,无法确定高度时,设置minHeight和maxHeight

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingHorizontal="@dimen/m24">
        ......
<com.xuexiang.xui.widget.textview.showalltextview.ShowAllTextView
    android:id="@+id/content_tv"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="6dp"
    android:maxHeight="@dimen/margin_60"
    android:minHeight="@dimen/margin_20"
    android:textColor="@color/color_ff666666"
    android:textSize="@dimen/textsize_14sp"
    app:layout_constraintStart_toStartOf="@id/title_tv"
    app:layout_constraintTop_toBottomOf="@+id/title_tv"
    tools:text="是味儿无热二是味儿无热二是味儿无热二二二二无若" />

<com.yzyz.oa.main.widge.PostImageLayout
    android:id="@+id/postLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/margin_8"
    android:maxHeight="@dimen/m200"
    android:minHeight="@dimen/alivc_common_margin_100"
    app:layout_constraintTop_toBottomOf="@+id/content_tv" />
    ......
</androidx.constraintlayout.widget.ConstraintLayout>