// 遍历viewGroup
public void traversalView(View view) {
if(null == view) {
return;
}
if(view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
LinkedList<ViewGroup> queue = new LinkedList<ViewGroup>();
queue.add(viewGroup);
while(!queue.isEmpty()) {
ViewGroup current = queue.removeFirst();
//dosomething
for(int i = 0; i < current.getChildCount(); i ++) {
if(current.getChildAt(i) instanceof ViewGroup) {
queue.addLast((ViewGroup) current.getChildAt(i));
}else {
//dosomething
}
}
}
}else {
//dosomething
}
}
Android 一种遍历ViewGroup的方法
最新推荐文章于 2024-06-17 03:22:01 发布