Подтвердить что ты не робот

Textview на (выше) Button, не работает в Android 5 (API 21)

Он выглядит как ошибка в 5 Android (API 21). Мне нужно текстовое изображение на кнопке, текст над ним должен быть установлен над кнопкой. Он работает корректно на Android 4.1 (API 16) и неверно на 5 Android (API 21). Есть скриншоты и код:

Android 4.1 - Это правильно, красный текст над кнопкой

Android 4.1

Android 5 - это неверно, красный текст под кнопкой!

Android 5

код:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent" >



<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:background="#00FF00">

    <Button
        android:id="@+id/bVio"
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:text="VIO"></Button>

    <TextView
        android:id="@+id/bVio_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00"
        android:textSize="12dip"
        android:textColor="#FFFFFF"
        android:background="@drawable/rounded_textbox"/>

    </FrameLayout>

</RelativeLayout>

rounded_textbox - это просто форма... если удалять фон, все выглядит так же, textview под кнопкой в ​​5 android.

Пожалуйста, совет!

4b9b3361

Ответ 1

Да. Это большой chnage в Android L (API 21). Появилась новая вещь - Elevation, это что-то вроде z-index в HTML. Поэтому, чтобы исправить эту ошибку, вам нужно использовать android: elevation = "100dp" OR android: translationZ = "100dip" для просмотра, который должен быть сверху. Поэтому правильный код:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rlBottom"
android:layout_width="fill_parent"
android:layout_height="match_parent" >



<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:background="#00FF00">

    <Button
        android:id="@+id/bVio"
        android:layout_width="wrap_content"
        android:layout_height="50dip"
        android:text="VIO"></Button>

    <TextView
        android:id="@+id/bVio_count"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="00"
        android:textSize="12dip"
        android:textColor="#FFFFFF"
        android:background="@drawable/rounded_textbox"
        android:elevation="100dp"/>

    </FrameLayout>

</RelativeLayout>