Sunday, June 12, 2011

How to perform exit animation for listview

Some would like to perform animations on list elements when listview is being made hidden or when listview is set to View.INVISIBLE, View.GONE.This is what i term it as "Exit animation of listview."


- listview has an api getChildCount() this will tell you how many number of list view elements are visible on screen and 'getChildAt(int)' api will give you the listview elements View instance.
- Get the childcount and iterate through the loop and get each child view instance and start a animation on each views, you will see a exit animation performed on it.


Below example shows how to perform alpha animation from 1 to 0, disappearing elements one by one from top to bottom.

public void startExitAnimation() {

Animation animation;
listcount = gridview.getChildCount();
int offsetTime=0;
animatedcount = 0;
for(int i=0;i {
View view = gridview.getChildAt(i);
animation = new AlphaAnimation(1.0f,0.0f);
animation.setAnimationListener(mExitAnimationListener);
animation.setFillAfter(true);
animation.setDuration(100);
animation.setStartOffset( i * 100);

if(view != null)
{
view.startAnimation(animation);
}
}
}

No comments:

Post a Comment