You could sort children by View.getLeft()
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
logCoordinates();
}
private void logCoordinates() {
RelativeLayout layout = (RelativeLayout)findViewById(R.id.layout);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
Log.i("tag", String.format("%d %d %d %d", child.getLeft(), child.getTop(), child.getRight(), child.getBottom()));
}
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
logCoordinates();
}
Please, compare log output of logCoordinates()
called from onCreate()
and from onWindowFocusChanged()
. View coordinates are not available within onCreate()
(why?).
See discussion here How to get height and width of Button