Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expandable listview setselectionfromTop with animation and padding

I enabled animation(expand and contract) to default android'd expandable listview using this https://github.com/idunnololz/AnimatedExpandableListView/blob/master/src/com/idunnololz/widgets/AnimatedExpandableListView.java.

However, the one limitation that I am facing is to move the current expanded click to the top.

I tried setSelectionFromTop(groupPosition, 0)

Here is the question:
- How to add animation to bringing it to the top?
- How to bring it to a top to a specific height. Lets say below 10px from the top.

Any pointers would be amazing.

Note: The solution should work from sdk 14 and above.

like image 269
amalBit Avatar asked May 12 '15 05:05

amalBit


2 Answers

Any pointers would be amazing.

You can use android-advancedrecyclerview. The recycler view itself is a powerful widget that has a lot of features but for your question you can take a look at MyExpandableItemAdapter.java.

  • How to add animation to bringing it to the top?

public void scrollToPosition (int position)

public void smoothScrollToPosition (int position)

  • How to bring it to a top to a specific height. Lets say below 10px from the top.

public void scrollBy (int x, int y)

public void smoothScrollBy (int dx, int dy)

like image 111
mmlooloo Avatar answered Nov 06 '22 17:11

mmlooloo


This with surely work with the library you used, i tired from my own let me know you need a sample.

long packedPosition = mListView.getPackedPositionForGroup(groupPosition);

final long flatpostion = mListView.getFlatListPosition(packedPosition);



expandableListView.expandGroupWithAnimation(groupPosition);



new Handler().postDelayed(new Runnable() {

    @Override

    public void run() {

        getActivity().runOnUiThread(new Runnable() {

            @Override

            public void run() {

                mListView.smoothScrollToPositionFromTop((int) flatpostion, HomeActivity.LIST_HEADER_HEIGHT, 200);

            }

        });

    }

}, 300);
like image 38
Vinay Chopra Avatar answered Nov 06 '22 16:11

Vinay Chopra