Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在RelativeLayout中获取子视图_Android_Layout - Fatal编程技术网

Android 在RelativeLayout中获取子视图

Android 在RelativeLayout中获取子视图,android,layout,Android,Layout,我想在活动中添加一个按钮,该按钮将返回相对布局的所有子视图 如何获取相对布局视图的所有子视图?RelativeLayout扩展了具有getChildCount()和getChildAt(int index)方法的ViewGroup。因此,您可以尝试的是: for(int i = 0; i < relativeLayout.getChildCount(); i++) { View child = relativeLayout.getChildAt(i); // your proc

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


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

RelativeLayout
扩展了具有
getChildCount()
getChildAt(int index)
方法的
ViewGroup
。因此,您可以尝试的是:

for(int i = 0; i < relativeLayout.getChildCount(); i++) {
   View child = relativeLayout.getChildAt(i);
   // your processing...
}
for(int i=0;i
只需查看子项计数,然后对每个子项进行迭代。 大概是这样的:

int childCount = myRelativeLayout.getChildCount();
for(int i = 0; i < childCount; i++) {
    View v = myRelativeLayout.getChildAt(i);
    // do whatever you want to with the view
}
int childCount=myRelativeLayout.getChildCount();
for(int i=0;i
希望这有帮助