调用notifyDataSetChanged()时,RecyclerView闪烁

时间:2018-08-15 05:59:20

标签: android android-recyclerview recyclerview-layout

我面临一个问题,当调用adapter.notifyDataSetChanged()adapter.notifyItemRangeChanged(0,recyclerView.getChildCount())时,适配器会闪烁。我已经尝试了许多解决方案,例如setHasStableIds(true),并且使用getItemId()来返回ID,但这对我没有帮助。

if (page == 1) {
    homeAdapter = new HomeAdapter(getActivity(), homeBeanList, Home.
    this, Home.
    this, Home.
    this, profile_pic, Home.
    this, Home.
    this, page);
    loaderDiloag.dismissDiloag();
    recyclerView.setAdapter(homeAdapter);
    recyclerView.setNestedScrollingEnabled(false);
} else {
    if (homeAdapter != null) {
        try {
            loaderDiloag.dismissDiloag();
            recyclerView.setNestedScrollingEnabled(false);
            homeAdapter.notifyItemRangeChanged(0, recyclerView.getChildCount());
        } catch (Exception e) {
            Log.e("error", e.toString() + "");
        }
    } else {
        try {
            homeAdapter = new HomeAdapter(getActivity(), homeBeanList, Home.
            this, Home.
            this, Home.
            this, profile_pic, Home.
            this, Home.
            this, page);
            loaderDiloag.dismissDiloag();
            recyclerView.setAdapter(homeAdapter);
            recyclerView.setNestedScrollingEnabled(false);
            homeAdapter.notifyDataSetChanged();
        } catch (Exception e) {
            Log.e("error", e.toString() + "");
        }
    }

1 个答案:

答案 0 :(得分:0)

尝试一下

private void removeBlinkAnimationWhenNewItemAdded(){
        ((SimpleItemAnimator)recyclerView).setSupportsChangeAnimations(false)
}