Search code examples
androidandroid-relativelayoutz-order

Defining Z order of views of RelativeLayout in Android


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

I know one way 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.


Solution

  • 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.

    Edit: This is documented here and here on the Android developer site. (Thanks @flightplanner)