RelativeLayout zorder lollipop

I have a small layout that works correctly on API 19: 4.2.2, but I can’t get it to work with API 21: 5.0.1.

Here is the layout:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <Button android:id="@+id/start_button" android:layout_width="match_parent" android:layout_height="match_parent" android:textStyle="bold" android:textSize="30sp" android:background="@color/start_button_bg" android:textColor="@color/start_button_text" android:text="@string/start_process"/> <TextView android:id="@+id/pro_icon" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:textColor="@android:color/white" android:background="@drawable/pro_icon" android:text="PRO" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium"/> </RelativeLayout> 

Really simple stuff. I just want the text to be above the Button in a relative layout. I know that the relative layout looks at the views in the order in which they are added to the xml, but it does not seem to work on candy. I cannot get the TextView to render above the button. Any idea?

Greetings.

+8
android android-layout android-5.0-lollipop
source share
1 answer

A Button by default has elevation on Android 5.0+; a TextView not. The height of the widget will basically cancel the Z-axis ordering set by the RelativeLayout or FrameLayout .

Your options:

  • Redesign your user interface so that you don’t have widgets ordered on the Z axis, or

  • Replace StateListAnimator with Button to modify or exclude elevation animations, or

  • Try changing the height of the TextView , via android:elevation , to be taller than Button

+15
source share

All Articles