带有动画和填充的可扩展列表视图集 selectionfromTop

Expandable listview setselectionfromTop with animation and padding

我使用这个 https://github.com/idunnololz/AnimatedExpandableListView/blob/master/src/com/idunnololz/widgets/AnimatedExpandableListView.java.

将动画(展开和收缩)启用为默认 android 的可展开列表视图

但是,我面临的一个限制是将当前展开的点击移动到顶部。

我试过了setSelectionFromTop(groupPosition, 0)

这里是问题:
- 如何添加动画使其到达顶部?
- 如何将它带到特定高度的顶部。让我们说从顶部低于 10px。

任何指点都会很棒。

注意:该解决方案应该适用于 sdk 14 及更高版本。

Any pointers would be amazing.

您可以使用 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)

这肯定适用于您使用的库,我对自己的库感到厌倦了让我知道您需要一个示例。

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);