Android Studio xml对象覆盖对象

Android Studio xml对象覆盖对象,android,xml,textview,numbers,display,Android,Xml,Textview,Numbers,Display,如何将文本视图放在xml文件中的按钮之前?我的文本视图总是在按钮后面。我正处于一种紧张的状态。我想在按钮的右上角打个小数字。我为那顶帽子做了一个可拉的,看起来不错。 如果有人能帮忙就好了!谢谢 xml: 请使用此布局将TextView置于按钮视图的顶部: 您需要在TextView中添加android:translationZ=10dp 你能分享你的xml布局吗?好的,我会这样做。开始的文本视图应该在按钮之前。请检查我下面的答案。希望对你有帮助。 <?xml version="1.0" en

如何将文本视图放在xml文件中的按钮之前?我的文本视图总是在按钮后面。我正处于一种紧张的状态。我想在按钮的右上角打个小数字。我为那顶帽子做了一个可拉的,看起来不错。 如果有人能帮忙就好了!谢谢

xml:


请使用此布局将TextView置于按钮视图的顶部:

您需要在TextView中添加android:translationZ=10dp


你能分享你的xml布局吗?好的,我会这样做。开始的文本视图应该在按钮之前。请检查我下面的答案。希望对你有帮助。
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="at.kessapps.cookieclicker.MainActivity">

    <TextView
        android:id="@+id/clicker_discount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/sale_corner"
        android:text="20%"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/shopbutton"
        app:layout_constraintRight_toRightOf="@id/shopbutton"
        app:layout_constraintTop_toTopOf="@id/shopbutton" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="350dp"
        android:layout_height="80dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.508"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/cooltext348859404219232" />

    <Button
        android:id="@+id/shopbutton"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:hapticFeedbackEnabled="false"
        android:onClick="toShop"
        android:text="Shop"
        android:drawableLeft="@drawable/ic_store"
        android:textColor="@color/colorWhite"
        android:paddingLeft="5dp"
        android:background="@drawable/button_neutral_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <ImageView
        android:id="@+id/onOption"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="16dp"
        android:layout_marginBottom="16dp"
        android:onClick="toOption"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/optionen" />

</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/MainLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="at.kessapps.cookieclicker.MainActivity">

    <TextView
        android:id="@+id/clicker_discount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:translationZ="10dp"
        android:background="@drawable/sale_corner"
        android:text="20%"
        android:textStyle="bold"
        app:layout_constraintBottom_toTopOf="@+id/shopbutton"
        app:layout_constraintRight_toRightOf="@id/shopbutton"
        app:layout_constraintTop_toTopOf="@id/shopbutton" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="350dp"
        android:layout_height="80dp"
        android:layout_marginTop="16dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.508"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/cooltext348859404219232" />

    <Button
        android:id="@+id/shopbutton"
        style="@style/Widget.AppCompat.Button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="16dp"
        android:layout_marginBottom="16dp"
        android:hapticFeedbackEnabled="false"
        android:onClick="toShop"
        android:text="Shop"
        android:drawableLeft="@drawable/ic_store"
        android:textColor="@color/colorWhite"
        android:paddingLeft="5dp"
        android:background="@drawable/button_neutral_background"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

    <ImageView
        android:id="@+id/onOption"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_marginStart="16dp"
        android:layout_marginBottom="16dp"
        android:onClick="toOption"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:srcCompat="@drawable/optionen" />

</androidx.constraintlayout.widget.ConstraintLayout>