码迷,mamicode.com
首页 > 其他好文 > 详细

ExpandableListView置顶和子list收放

时间:2015-12-23 17:49:10      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

  private int sign = -1;
  result_list.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView parent, final View v, int groupPosition, long id) {
                final View view = result_list.getChildAt(0);
                final int p = groupPosition;
                if(sign == -1){
                    result_list.expandGroup(groupPosition);
                    scroll(result_list, p, view);
                    sign = groupPosition;
                }else if(sign == groupPosition){
                    result_list.collapseGroup(sign);
                    sign = -1;
                }else{
                    result_list.collapseGroup(sign);
                    result_list.expandGroup(groupPosition);
                    scroll(result_list, p, view);
                    sign = groupPosition;
                }
                return true;
            }
        });

  //控制滑动
    public static void scroll(final ExpandableListView result_list,final int position,final View view){
        new Handler().post(new Runnable() {
            @Override
            public void run() {
                if (android.os.Build.VERSION.SDK_INT >= 11) {
                    result_list.smoothScrollToPositionFromTop((position - 1),
                            -view.getHeight(), 300);
                }
            }
        });
    }

 

ExpandableListView置顶和子list收放

标签:

原文地址:http://www.cnblogs.com/wei1228565493/p/5070641.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!