Android 数据集更改而未完全刷新时的RecyclerView/Diffitls动画

Android 数据集更改而未完全刷新时的RecyclerView/Diffitls动画,android,android-recyclerview,android-animation,android-adapter,android-diffutils,Android,Android Recyclerview,Android Animation,Android Adapter,Android Diffutils,我想要两样东西: 删除RecyclerView中的项目时不重新加载/刷新适配器(不使用notifyDatasetChanged) 为了做到这一点,我使用了DiffUtils,它工作得非常好。但是我还想保留RecyclerView的DefaultItemAnimator,它显然对DiffUtils没有影响 因此,我的问题是:如何在不刷新所有数据集的情况下删除/更新项目,并保持与DefaultItemAnimator类似的动画 我知道很多帖子都给出了关于RecyclerView的答案,但没有一篇

我想要两样东西:

  • 删除RecyclerView中的项目时不重新加载/刷新适配器(不使用
    notifyDatasetChanged
  • 为了做到这一点,我使用了DiffUtils,它工作得非常好。但是我还想保留
    RecyclerView
    DefaultItemAnimator
    ,它显然对DiffUtils没有影响
因此,我的问题是:如何在不刷新所有数据集的情况下删除/更新项目,并保持与
DefaultItemAnimator
类似的动画

我知道很多帖子都给出了关于
RecyclerView
的答案,但没有一篇适合我的需要。 我知道
notifyItemRemoved
notifyItemRangeChanged
,但它们也会刷新所有数据集

谢谢

编辑提供一些代码以便更好地理解:

在我的适配器中,我使用了两种方法:这是在特定位置删除视图的方法

//适配器方法
无效删除(内部位置){
数据列表。删除(位置);
recyclerView.removeViewAt(位置);
更新列表(数据列表);
}
无效更新列表(ArrayList newList){
DiffUtil.DiffiesUlt DiffiesUlt=DiffUtil.calculateDiff(新的DiffutilTheme(旧列表,新列表));
diffResult.dispatchUpdatesTo(本);
}
这是我的DiffUtils课程:

public class DiffUtils extends DiffUtil.Callback{

    ArrayList<MyModel> oldItems;
    ArrayList<MyModel> newItems;

    public DiffUtils(ArrayList<MyModel> newItems, ArrayList<MyModel> oldItems) {
        this.newItems = newItems;
        this.oldItems = oldItems;
    }

    /**
     *  It returns the size of the old list.
     * @return
     */
    @Override
    public int getOldListSize() {
        return oldItems.size();
    }

    /**
     * Returns the size of the new list;
     * @return
     */
    @Override
    public int getNewListSize() {
        return newItems.size();
    }

    /**
     * Called by the DiffUtil to decide whether two object represent the same Item.
     * Here we check the names because we know they are unique.
     * @param oldItemPosition
     * @param newItemPosition
     * @return
     */
    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        // We are sure that the names are unique
        return oldItems.get(oldItemPosition).getItemName().equals(newItem.get(newItemPosition).getItemName());
    }

    /**
     * Checks whether two items have the same data.
     * This method is called by DiffUtil only if areItemsTheSame returns true.
     * @param oldItemPosition
     * @param newItemPosition
     * @return
     */
    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        return oldItems.get(oldItemPosition).equals(newItems.get(newItemPosition));
    }

    /**
     * If areItemTheSame return true and areContentsTheSame returns false DiffUtil calls this method to get a payload about the change.
     * @param oldItemPosition
     * @param newItemPosition
     * @return
     */
    @Nullable
    @Override
    public Object getChangePayload(int oldItemPosition, int newItemPosition) {

        return super.getChangePayload(oldItemPosition, newItemPosition);
    }
}


这也是工作和动画,但刷新了所有其他项目。

请提供适当的代码,以便我可以更好地了解我已经更新了我的帖子,让我知道它是否可以理解。您还可以告诉我您的基本要求是什么吗?您希望删除项目上的哪个动画??与
RecyclerView
中的
DefaultItemAnimator
相同或类似
void removeAt(int position) {
     dataList.remove(position);
     notifyItemRemoved(position);
     notifyItemRangeChanged(position, dataList.size());
     }