Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

animating the childs of an expandablelistview when collapsing/expanding

I'm trying to animate my child views in an expandablelistview. I would like the child view to slide down from top to bottom when expanding a group and sliding from bottom to top when collapsing a group. I've looked at several methods (animating the viewgroup or the child views) but none seem to work very well or I'm not doing it right.

I've extended a class from BaseExpandableListAdapter to create my own custom adapter. I also have custom (xml) views for the groups/childs which I inflate in the getChildView and getGroupView methods.

I would only like the current collapsed/expanded group to animate it's child. Can anyone point me in the right direction? If you need more information or code please let me know!

Regards, Ivo

like image 274
ivov Avatar asked Dec 27 '10 19:12

ivov


2 Answers

So what I've done is to use a regular listview and then animate the row views when clicked.

I use this methode for animation: Android animate drop down/up view proper

It can be a bit tricky if the height for the view to be dropped down is wrap_content, for this problem I had to find and set the height before I start the animation:

public static void setHeightForWrapContent(Activity activity, View view) {
    DisplayMetrics metrics = new DisplayMetrics();
    activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    int screenWidth = metrics.widthPixels;

    int heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
    int widthMeasureSpec = MeasureSpec.makeMeasureSpec(screenWidth, MeasureSpec.EXACTLY);

    view.measure(widthMeasureSpec, heightMeasureSpec);
    int height = view.getMeasuredHeight();
    view.getLayoutParams().height = height;
}

The view should be gone before the animation start and then made visible when animation starts.

Edit: I made a complete example here.

like image 127
Warpzit Avatar answered Oct 11 '22 16:10

Warpzit


You can add animation to each child view in the bindChildView method. In order to animate only the current group's child - just catch the onExpand event, read it's childs, save the ids on some array, and on the bindChildView - animate only the childs saved on that array.

like image 30
Udinic Avatar answered Oct 11 '22 18:10

Udinic