How to Animate Addition or Removal of Android ListView Rows
Animation anim = AnimationUtils.loadAnimation( GoTransitApp.this, android.R.anim.slide_out_right );anim.setDuration(500);listView.getChildAt(index).startAnimation(anim );new Handler().postDelayed(new Runnable() { public void run() { FavouritesManager.getInstance().remove( FavouritesManager.getInstance().getTripManagerAtIndex(index) ); populateList(); adapter.notifyDataSetChanged(); }}, anim.getDuration());
for top-to-down animation use :
<set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:fromYDelta="20%p" android:toYDelta="-20" android:duration="@android:integer/config_mediumAnimTime"/> <alpha android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_mediumAnimTime" /></set>
The RecyclerView
takes care of adding, removing, and re-ordering animations!
This simple AndroidStudio project features a RecyclerView
. take a look at the commits:
Take a look at the Google solution. Here is a deletion method only.
ListViewRemovalAnimation project code and Video demonstration
It needs Android 4.1+ (API 16). But we have 2014 outside.