Custom animation when item removed in recycleview

40 Views Asked by At

I'm trying to fade out items when it's removed then collapse recycleview. But it doesn't work. Please help me

for(Object appData : mInvisibleEntries){
       mVisibleEntries.remove(appData);
}

for(View view:viewHoldersList){
       Animation a = new AlphaAnimation(1.00f, 0.00f);
       a.setDuration(2000);
       view.startAnimation(a);
}
notifyItemRangeRemoved(MAX_VISIBLE_APPS_COUNT + 1, mInvisibleEntries.size());
collapseRv();

private void collapseRv(){
    final int initialHeight = mRecyclerView.getMeasuredHeight();
    ValueAnimator valueAnimator = ValueAnimator.ofInt(initialHeight,HEIGHT_VIEW_APPDATA*3+HEIGHT_SECTION_FOOTER);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRecyclerView.getLayoutParams().height = (int) animation.getAnimatedValue();
            mRecyclerView.requestLayout();
        }
    });
    valueAnimator.setInterpolator(new DecelerateInterpolator());
    valueAnimator.setDuration(2000);
    valueAnimator.start();
}
1

There are 1 best solutions below

1
Shayan Samad On

To make it simlpe, You can use library like https://github.com/wasabeef/recyclerview-animators