简体   繁体   English

在RelativeLayout中获取子视图

[英]Get Child view in a RelativeLayout

I want to add one button in my activity that will return all child view of relative layout. 我想在我的活动中添加一个按钮,该按钮将返回相对布局的所有子视图。

How can i get all child view of relative layout view? 如何获取相对布局视图的所有子视图?

RelativeLayout extends ViewGroup which has the getChildCount() and getChildAt(int index) methods. RelativeLayout扩展了具有getChildCount()getChildAt(int index)方法的ViewGroup So what you could try is: 因此,您可以尝试的是:

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

Just the child count for the view and iterate over each of them. 只是孩子对视图进行计数并遍历每个视图。 Something like this : 像这样的东西:

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

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM