views:

621

answers:

1

I would like to define the z order of the views of a RelativeLayout in Android.

I know one of doing this is calling bringToFront.

Is there are better way of doing this? It would be great if I could define the z order in the layout xml.

+4  A: 

The easiest way is simply to pay attention to the order in which the Views are added to your XML file. Lower down in the file means higher up in the Z-axis.

Steve H
Thanks Steve H! Is this feature documented somewhere? I wouldn't want my layout to break in a new Android version.
hgpc
Hmm, I'm not sure. I'll dig around later to see what I can find. However the same principle is used elsewhere; canvases (used for 2d graphics) work the same way. So I suspect this won't change. Still, it's a good thing to check.
Steve H
This is unfortunately not always possible to change. For example, in a relative layout, each elements can only be layed out with respect to those previously defined in the file
Casebash