在RelativeLayout中获取子视图

Lal*_*tar 7 layout android

我想在我的活动中添加一个按钮,它将返回相对布局的所有子视图.

如何获得相对布局视图的所有子视图?

Ovi*_*tcu 34

RelativeLayout扩展ViewGroup哪个有getChildCount()getChildAt(int index)方法.所以你可以尝试的是:

for(int i = 0; i < relativeLayout.getChildCount(); i++) {
   View child = relativeLayout.getChildAt(i);
   // your processing...
}
Run Code Online (Sandbox Code Playgroud)