Defining Z order of views of RelativeLayout in Android Defining Z order of views of RelativeLayout in Android android android

Defining Z order of views of RelativeLayout in Android


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)


If you want to do this in codeyou can do

View.bringToFront();

see docs


Please note, buttons and other elements in API 21 and greater have a high elevation, and therefore ignore the xml order of elements regardless of parent layout. Took me a while to figure that one out.