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
希望这有帮助