如何使按钮 3 和相对布局(带有蓝色背景)都位于按钮 2 的前面?它们在组件树中都较高(值(value)),但 Button 2 仍然位于所有组件的前面。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="75dp"
android:layout_marginTop="64dp"
android:text="Button 2" />
<RelativeLayout
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignStart="@+id/button2"
android:layout_alignTop="@+id/button2"
android:layout_marginStart="48dp"
android:background="@android:color/holo_blue_bright"
android:id="@+id/relativeLayout">
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/relativeLayout"
android:layout_alignTop="@+id/button2"
android:layout_marginStart="11dp"
android:layout_marginTop="17dp"
android:text="Button 3" />
</RelativeLayout>
最佳答案
答案就在 material design specs 。凸起按钮(即未应用 style
的按钮)的默认高度为 2dp
,而 RelativeLayout
的默认高度为 0dp
。
我的建议是将 style="@style/Widget.AppCompat.Button.Borderless"
应用于 button2
。然后它有 0dp
海拔。如果您想要彩色按钮,请对其应用 android:background
。
关于java - 布局问题;重叠按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45220429/