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 is a view group that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout area (such as aligned to the bottom, left or center).
LinearLayout : is a ViewGroup that aligns all children in a single direction, vertically or horizontally. RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets.
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...
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With