1.ListView的Item动画删除
思路:将删除的Item的高度缩小至0,到到达为零时,恢复原来的高度,在ListView的数据源list中删除该条目刷新adapter,参考并加以更改
代码:
* Item缩放的动画
*
* @param view
* @param al
* 这个Item动画不仅仅可以缩小高度,也可以左右滑动删除等
*/
public static void collapse(final View view, Animation.AnimationListener al) {
final int originHeight = view.getMeasuredHeight();
Animation animation = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (interpolatedTime == 1.0f) {
view.getLayoutParams().height = originHeight;//更改部分避免删除两个Item
} else {
view.getLayoutParams().height = originHeight - (int) (originHeight * interpolatedTime);
}
view.requestLayout();
}
@Override
public boolean willChangeBounds() {
return true;
}
};
if (al != null) {
animation.setAnimationListener(al);
}
animation.setDuration(300);
view.startAnimation(animation);
}
/**
* 删除Item动画
*@param view所要删除的convertView
* @param position
*/
private void deleteItem( View view,final int position) {
Animation.AnimationListener al = new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
list.remove(position);
adapter.notifyDataSetChanged();
}
@Override
public void onAnimationRepeat(Animation animation) {
}
};
collapse(view, al);
}
2.RecycleView的Item删除与局部刷新
RecycleView自带局部刷新以及删除动画处理
mRecyclerView.setItemAnimator(new DefaultItemAnimator());//可以自定义继承自SimpleItemAnimator的动画加以处理
mRecyclerView.notifyItemChanged(int position)。//刷新单个数据