获取子视图中的RelativeLayout视图、RelativeLayout

2023-09-08 09:58:51 作者:三分靠运气七分靠打拼

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

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的扩展的ViewGroup 里面有 getChildCount() getChildAt(INT指数)方法。所以你可以尝试的是:

RelativeLayout extends ViewGroup which has the getChildCount() and getChildAt(int index) methods. So what you could try is :

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