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.

11/17/2018 12:56:40 AM

Accepted Answer

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)

1/12/2015 6:09:33 PM

If you want to do this in code you can do


see docs

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow