view的分层显示

3 篇文章 0 订阅
1 篇文章 0 订阅
private void insertChildToWindowParent(WindowManager windowManager, WindowManager.LayoutParams lp) {
        if (windowManager == null || mChild == null) {
            return;
        }

        for(View childView : windowChildViewList)
        {
            windowManager.removeView(childView);
        }

        int count = windowChildViewList.size();

        int oldChildLevel = -1;
        int mChildLevel = mWindowLevel;
        if (count == 0) {
            mChild.setTag(R.id.teleport_level_tag, mWindowLevel);
            mChild.setLayoutParams(lp);
            windowChildViewList.add(mChild);
        }
        for (int i = 0; i < count; i++) {
            oldChildLevel = getWindowChildLevel(windowChildViewList,i);
            if (mChildLevel < oldChildLevel && i == 0) {
                mChild.setTag(R.id.teleport_level_tag, mChildLevel);
                windowChildViewList.add(i,mChild);
                mChild.setLayoutParams(lp);
                break;
            }
            else if((mChildLevel >= oldChildLevel && i == count - 1)
                    ||(mChildLevel >= oldChildLevel && i < count-1 && mChildLevel < getWindowChildLevel(windowChildViewList,i+1)))
            {
                mChild.setTag(R.id.teleport_level_tag, mChildLevel);
                windowChildViewList.add(i+1 , mChild);
                mChild.setLayoutParams(lp);
                break;
            }
        }

        for(View childView : windowChildViewList)
        {
            WindowManager.LayoutParams childLp = (WindowManager.LayoutParams) childView.getLayoutParams();
            windowManager.addView(childView,childLp);
        }
    }

    private void insertChildToActivityParent(ViewGroup parent, ViewGroup.LayoutParams layoutParams) {
        if (parent == null || mChild == null) {
            return;
        }
        int count = parent.getChildCount();
        int mChildLevel = mWindowLevel;

        int oldChildLevel = -1;

        if (count == 0) {
            mChild.setTag(R.id.teleport_level_tag, mChildLevel);
            parent.addView(mChild, layoutParams);
        }
        for (int i = 0; i < count; i++) {
           oldChildLevel = getParentChildLevel(parent,i);
            if (mChildLevel < oldChildLevel && i == 0) {
                mChild.setTag(R.id.teleport_level_tag, mChildLevel);
                parent.addView(mChild, i, layoutParams);
                break;
            }
            else if((mChildLevel >= oldChildLevel && i == count - 1)
                    ||(mChildLevel >= oldChildLevel && i < count-1 && mChildLevel < getParentChildLevel(parent,i+1)))
            {
                mChild.setTag(R.id.teleport_level_tag, mChildLevel);
                parent.addView(mChild, i+1, layoutParams);
                break;
            }
        }
    }

    private int getParentChildLevel(ViewGroup parent, int index) {
        int level = -1;
        View oldChild = parent.getChildAt(index);
        if (oldChild != null) {
            Object oldChildLevelObject = oldChild.getTag(R.id.teleport_level_tag);
            if (oldChildLevelObject != null) {
                level= (int) oldChildLevelObject;
            }
        }
        return level;
    }

    private int getWindowChildLevel(ArrayList<View> childList,int index) {
        int level = -1;
        View oldChild = childList.get(index);
        if (oldChild != null) {
            Object oldChildLevelObject = oldChild.getTag(R.id.teleport_level_tag);
            if (oldChildLevelObject != null) {
                level= (int) oldChildLevelObject;
            }
        }
        return level;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值