AnimatedExpandableListView,解决你所有对于ExpandableListView的疑惑

先说一下我对于这个demo的应用场景,说来也是心酸的血泪史,现在的需求也是改了很多遍改成这样的,先上原型,首先来说必须要感谢伟大的设计:这其实是放在Activity里面的一个原型图,有点小Bug
说起来也就是一个ExpandableListView,但是要想让他不土鳖,有人样其实没有这么简单,下面简单介绍一下这个实现的功能有什么不同之处

  1. ExpandableListView 的展开和闭合是有动画的,是一个渐进展开的过程,一改Native的死板,这是对于一个网络作品AnimatedExpandableListView的修改
    闭合:
 public boolean collapseGroupWithAnimation(int groupPos) {
        int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos));
        if (groupFlatPos != -1) {
            int childIndex = groupFlatPos - getFirstVisiblePosition();
            if (childIndex >= 0 && childIndex < getChildCount()) {
                // Get the view for the group is it is on screen...
                View v = getChildAt(childIndex);
                if (v.getBottom() >= getBottom()) {
                    return collapseGroup(groupPos);
                }
            } else {
                // If the group is offscreen, we can just collapse it without an
                // animation...
                return collapseGroup(groupPos);
            }
        }

展开

  @SuppressLint("NewApi") 
    public boolean expandGroupWithAnimation(int groupPos) {
        boolean lastGroup = groupPos == adapter.getGroupCount() - 1;
        if (lastGroup && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            return expandGroup(groupPos, true);
        }

        int groupFlatPos = getFlatListPosition(getPackedPositionForGroup(groupPos));
        if (groupFlatPos != -1) {
            int childIndex = groupFlatPos - getFirstVisiblePosition();
            if (childIndex < getChildCount()) {
                View v = getChildAt(childIndex);
                if (v.getBottom() >= getBottom()) {
                    adapter.notifyGroupExpanded(groupPos);
                    return expandGroup(groupPos);
                }
            }
        }

这里不贴详细的代码,有兴趣的童鞋可以参见AnimatedExpandableListView

  1. .解决自定义箭头样式位置的问题,并将原先的奇丑无比的箭头去掉

a.首先去掉Native的箭头

 private AnimatedExpandableListView listView;
 listView = (AnimatedExpandableListView)view.findViewById(R.id.listView);
 listView<
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值