Android - 将对象彼此放在相对布局上

Android - Put object each others on Relative Layout

我需要将 TextView 放在 RelativeLayout 中的 Button 之上,所以我将 TextView 放在 Button 之前,但它不起作用

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
                android:id="@+id/textView"
                android:layout_width="20pt"
                android:layout_height="22pt"
                android:layout_gravity="start"
                android:layout_marginTop="4pt"
                android:background="@drawable/rounded_numbers"
                android:gravity="center"
                android:text="1" />
        <Button
                android:id="@+id/peso_but"
                android:layout_width="100pt"
                android:layout_height="20pt"
                android:layout_marginStart="17pt"
                android:layout_marginTop="5pt"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#3399ff"
                android:fontFamily="@font/fira_sans_semibold"
                android:text="Button"
                android:textColor="#f5f5f5"
                android:textSize="8pt" />
</RelativeLayout>

据我所知,将一个对象放在另一个对象之前应该行得通,但行不通

将此添加到您的按钮

android:layout_below="@+id/textView"

试试这个你需要使用 FrameLayout 来相互重叠视图

   <FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/peso_but"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#888"
        android:backgroundTint="#3399ff"
        android:text="Button"
        android:textColor="#f5f5f5"
        android:textSize="8pt" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/black"
        android:textColor="@color/white"
         android:gravity="center"
        android:elevation="100dp"
        android:text="1" />

</FrameLayout>

如果您希望 TextViewButton 重叠,请将 RelativeLayout 替换为 FrameLayout。

在 TextView 中试试这一行

android:layout_abov="@+id/peso_but"