tjerkw / Android-SlideExpandableListView

A better ExpandableListView, with animated expandable views for each list item
Apache License 2.0
1.98k stars 741 forks source link

On open, the expandable part jumps open to full before animating #63

Open sebastian-ruiz opened 10 years ago

sebastian-ruiz commented 10 years ago

On pressing the expandable handle, the expandable section jumps open without animation, and immediately afterwards it animates open.

I am using it as follows:

    mainListView = (DragSortListView) root.findViewById(R.id.main_listview);

        mainListView.setAdapter(
                new SlideExpandableListAdapter(
                        ((MainActivity)getActivity()).myNinjaAdapter,
                        R.id.expandable_toggle_button,
                        R.id.expandable
                )
        );

Any help would be greatly appreciated.

tjerkw commented 10 years ago

Yes, this is by design. I didnt know how to calculate a view height before displaying it.

If you have a solution please tell me! I tried a lot of stuff.

Lonli-Lokli commented 10 years ago

Maybe it'll be enough to remember the view height after the first animation?

julioz commented 9 years ago

I've seen other libraries using onPreDrawListener for this kind of calculation, maybe it is the way to treat this.

fsbarata commented 9 years ago

I'm managed to fix it. AbstractSlideExpandableListAdapter.java

public View getView(int position, View view, ViewGroup viewGroup) {
        this.parent = viewGroup;
        view = wrapped.getView(position, view, viewGroup);
        final View finalView = view;
        final ViewTreeObserver viewTreeObserver = view.getViewTreeObserver();
        viewTreeObserver.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                finalView.getViewTreeObserver().removeOnPreDrawListener(this);
                enableFor(finalView, position);
                return true;
            }
        });

        return view;
}

...

public void enableFor(View parent, int position) {
        View more = getExpandToggleButton(parent);
        View itemToolbar = getExpandableView(parent);
        enableFor(more, itemToolbar, position);
}