版权声明:转载请注明出处 https://blog.csdn.net/l707941510/article/details/82912526
要求不能用递归的方式实现
// 遍历viewGroup
public void traverseViewGroup(View view) {
if(null == view) {
return;
}
if(view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
LinkedList<ViewGroup> linkedList = new LinkedList<>();
linkedList.add(viewGroup);
while(!linkedList.isEmpty()) {
ViewGroup current = linkedList.removeFirst();
//dosomething
for(int i = 0; i < current.getChildCount(); i ++) {
if(current.getChildAt(i) instanceof ViewGroup) {
linkedList.addLast((ViewGroup) current.getChildAt(i));
}else {
//dosomething
}
}
}
}else {
//dosomething
}
}