您现在的位置是:网站首页> Android
遍历view中的子view
- Android
- 2022-03-10
- 820人已阅读
摘要
private List<View> getAllChildViews(View view) {
List<View> allchildren = new ArrayList<View>();
if (view instanceof ViewGroup) {
ViewGroup vp = (ViewGroup) view;
for (int i = 0; i < vp.getChildCount(); i++) {
View viewchild = vp.getChildAt(i);
allchildren.add(viewchild);
//再次 调用本身(递归)
allchildren.addAll(getAllChildViews(viewchild));
}
}
return allchildren;
}