1

I'm trying to make the childs of my ExpandableListView to show up with an animation. Since I'm using the Android 2.2 API, I can't use the expandGroup(int groupPos, boolean animate) method

I'm using an animation I got from here: Android animate drop down/up view proper

and I'm setting it to my convertView in the getChildView method of my ExpandableListView Adapter like this:

public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
        View convertView, ViewGroup parent) {

           ...

    ExpandCollapseAnimation animation = new ExpandCollapseAnimation(convertView, 500, 0);
    convertView.setAnimation(animation);
    return convertView;
}

When I click a Group of the ExpandableListView, first it shows all the childs with no animation, and then immediately does the expand animation on all childs like I want.

I need it to just show the animations. Any Help would be very greatful.

Community
  • 1
  • 1
Ghar
  • 625
  • 1
  • 7
  • 19

1 Answers1

0

In short, its extremely hard and many people say its not possible to do this. It is one of the few shortcomings of the android ListView/ExpandableListView. If you notice, when you call the expandGroup(int groupPosition) method on your ExpandableListView, there is a method that has a second paramater, a boolean for whether or not to animate it. This second animation method has been around since api level 14 which isn't much help to those of us wanting to animate a child view on android 2.3.3 and below.

the reason it displays the children and then animates them is because in Java, each line is run one after another. So you are expanding a group view and then the next lines are the animation lines. Thats just how java is. But to properly animate the child of the group view you have to override a method within the ExpandableListView class itself. i dont recommend it, because its a lot of work

the best workaround that I have come across is to initially set the height of the child to 0 pixels. this way when the android OS lays out your view, it seems as if it isnt there. then you animate your child going from 0 pixels height to your desired height. hope that helps!

JoshA
  • 133
  • 1
  • 11
  • 2
    Sorry but Java has nothing to do with it. And the argument of "execute one line after another" is a very simplistic view of computer architecture. – AngraX Dec 04 '12 at 03:56