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;
}
view的分层显示
最新推荐文章于 2021-05-25 19:57:31 发布