java - Android Studio: Button always appears at the front -


i have relativelayout add views.

i added button it, , button appears in front of other views added it, regardless of order in things added. how come?

i'm coding purely in java, no xml.

here's simple example, button appear here in front of text, though text added last:

protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      relativelayout layout = new relativelayout(this);      button button = new button(this);     textview text = new textview(this);      button.settext("button");     text.settext("text");      layout.addview(button);     layout.addview(text);      setcontentview(layout); } 

starting lollipop, statelistanimator controlling elevation added default button style. in experience, forces buttons appear above else regardless of placement in xml (or programmatic addition in case). might you're experiencing.

to resolve can add custom statelistanimator if need or set null if don't.

xml:

android:statelistanimator="@null" 

java:

button button = new button(this); button.settext("button"); if (build.version.sdk_int >= build.version_codes.lollipop) {     button.setstatelistanimator(null); } 

more details: android 5.0 android:elevation works view, not button?