我需要在RelativeLayout的Button上放置一个TextView,所以我把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>
据我所知,将一个物体放在另一个物体之前应该有效,但事实并非如此
试试这个你需要使用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>
如果你想要TextView
重叠Button
用FrameLayout替换你的RelativeLayout。
将其添加到您的按钮
android:layout_below="@+id/textView"
在TextView中尝试此行
android:layout_abov="@+id/peso_but"