头像Instagram的列表视图消失 [英] Header in listview like instagram disappears

查看:169
本文介绍了头像Instagram的列表视图消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表视图中的一个问题。如果我滚动列表,一切都很好。但如果我点击复选框,头消失。我查了一下,notifyOfChange()未启动。我认为,这是由于看图纸。谁知道如何使头在最后一个实例绘制。
我用下面的code:

  @覆盖
公共无效onScroll(AbsListView观点,诠释firstVisibleItem,诠释visibleItemCount,诠释totalItemCount){    //列表视图只有几个孩子(当然根据每个孩子的高度)谁是看得见
    的for(int i = 0; I< list.getChildCount();我++)
    {
        查看孩子= list.getChildAt(I)
        MuscleViewHolder支架=(MuscleViewHolder)child.getTag();        //如果视图是第一项在顶部我们会做一些处理
        如果(我== 0)
        {
            布尔isAtBottom = child.getHeight()&下; = holder.headerLayout.getBottom();
            诠释偏移量=持有者previousTop - child.getTop()。
            如果((isAtBottom&安培;!&安培;偏移大于0))
            {                。持有人previousTop = child.getTop();
                holder.headerLayout.offsetTopAndBottom(偏移);                holder.headerLayout.invalidate();
            }        } //如果视图不是第一个项目是可能,因为需要的角度再利用一些修正
        否则如果(holder.headerLayout.getTop()!= 0)
        {
            INT偏移= -1 * holder.headerLayout.getTop();
            holder.headerLayout.offsetTopAndBottom(偏移);
            。支架previousTop = 0;
            holder.headerLayout.invalidate();
        }
    }
}


解决方案

这个问题就解决了​​。我更换code以下

  IF((isAtBottom&安培;!&安培;偏移大于0)){
                holder.set previousTop(child.getTop());
                如果(itNotScroll){
                    holder.getHeaderLayout()offsetTopAndBottom(-holder.get previousTop());
                    itNotScroll = FALSE;
                }其他{
                    holder.getHeaderLayout()offsetTopAndBottom(偏移)。
                }
                holder.getHeaderLayout()无效()。
            }

然而,我这样做了,这样就可以在列表视图用不了两年时间只开一个单元

I have a problem in listview. If I scroll list, all is good. But if I click on checkbox, header disappears. I checked, notifyOfChange() not started. I think this is due to the drawing of view. Who knows how to make the header is drawn in the last instance. I use the following code:

@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

    //the listview has only few children (of course according to the height of each child) who are visible
    for(int i=0; i < list.getChildCount(); i++)
    {
        View child = list.getChildAt(i);
        MuscleViewHolder holder = (MuscleViewHolder) child.getTag();

        //if the view is the first item at the top we will do some processing
        if(i == 0)
        {
            boolean isAtBottom = child.getHeight() <= holder.headerLayout.getBottom();
            int offset = holder.previousTop - child.getTop();
            if(!(isAtBottom && offset > 0))
            {

                holder.previousTop = child.getTop();
                holder.headerLayout.offsetTopAndBottom(offset);

                holder.headerLayout.invalidate();
            }

        } //if the view is not the first item it "may" need some correction because of view re-use
        else if (holder.headerLayout.getTop() != 0)
        {
            int offset = -1 * holder.headerLayout.getTop();
            holder.headerLayout.offsetTopAndBottom(offset);
            holder.previousTop = 0;
            holder.headerLayout.invalidate();
        }
    }
}

解决方案

The problem is solved. I replace the code to the following

 if(!(isAtBottom && offset > 0)) {
                holder.setPreviousTop(child.getTop());
                if(itNotScroll){
                    holder.getHeaderLayout().offsetTopAndBottom(-holder.getPreviousTop());
                    itNotScroll = false;
                } else {
                    holder.getHeaderLayout().offsetTopAndBottom(offset);
                }
                holder.getHeaderLayout().invalidate();
            }

And yet, I did so, so that you can open only one element in expaned listview

这篇关于头像Instagram的列表视图消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆