BaseRecyclerViewAdapterHelper
我是使用第三方 BaseRecyclerViewAdapterHelper 作為RecyclerView的 adapter最易。
直達 BaseRecyclerViewAdapterHelper 庫
先看效果
首先BRVAH這個庫已經支持了加載動畫垮衷,使用起來很方便捏题,實現加載動畫的具體方法在這里 华临,加載動畫默認提供5種方法(漸顯、縮放伸辟、從下到上棚蓄,從左到右溶推、從右到左),當然也支持自定義的動畫效果帅霜。
添加刪除動畫也很簡單
1. 在Adapter 中添加刪除動畫匆背,執(zhí)行清理數據的操作
public class MyAdapter extends BaseQuickAdapter<ItemBean,BaseViewHolder> {
private final Resources resources;
List itemList = new ArrayList<View>();
BaseViewHolder mBaseViewHolder;
public MyAdapter(int layoutResId, List data) {
super(layoutResId, data);
resources = Utils.getApp().getResources();
}
@Override
protected void convert(BaseViewHolder baseViewHolder, ItemBean ItemBean) {
//設置item 顯示數據的地方
}
// 刪除動畫
public void removeData(final int position) {
ObjectAnimator scaleX = ObjectAnimator.ofFloat(itemList.get(position), "TranslationX", 0, 1000);
scaleX.setDuration(500);
scaleX.start();
scaleX.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
//刪除數據
notifyItemRemoved(position);
//如果不是按照順序刪除就需要整體刷新
// notifyDataSetChanged();
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
//刪除數據
notifyItemRemoved(position);
//如果不是按照順序刪除就需要整體刷新
// notifyDataSetChanged();
}
});
}
}
2. 外部只需要調用Adapter 的removeData 方法就可以刪除數據,并顯示動畫效果
MyAdapter.removeData(itemCount);
就是這么簡單的實現刪除動畫效果身冀。
BRVAH庫添加動畫的具體實現方法 BaseRecyclerAdapter之添加動畫(策略模式)钝尸,詳細講解在哪添加動畫、控制動畫執(zhí)行次數等內容搂根。