不会为adapter.notifyItemRangeInserted调用ItemAnimator runPendingAnimations

时间:2018-04-23 08:39:42

标签: android android-recyclerview android-animation

我已经实现了自定义itemAnimator。我将这个自定义动画师分配给了recyclerview适配器。要填充recyclerview,我调用notifyItemRangeInserted方法而不是适配器上的notifyDatasetChanged。麻烦是即使在调用notifyItemRangeInserted方法之后也永远不会调用动画代码(runPendingAnimations)。我发现这令人困惑..请在我的代码下面找到并告诉我,如果我错过了什么。谢谢!

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    mAdapter = new CountryAdapter(mCountryList);
    recCountry.setAdapter(mAdapter);
    recCountry.setLayoutManager(layoutManager);
    //1. Created own instance of DefaultAnimator
    final MyItemAnimator animator = new MyItemAnimator();
    //2. Set animator parameters
    animator.setAddDuration(duration);
    animator.setRemoveDuration(duration);
    animator.setChangeDuration(duration);
    recCountry.setItemAnimator(animator);
    mAdapter.notifyItemRangeInserted(0,mCountryList.size());}

奇怪的是当我调用notifyItemRangeChanged来更新适配器时,调用runPendingAnimations方法。有什么想法吗?

0 个答案:

没有答案