如何在 RelativeLayout
中将一个 Button
重叠到另一个上?
谢谢。
这是我试过的。谢谢
<RelativeLayout
android:id="@+id/category"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_vertical|center_horizontal|center"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/btn2"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:src="@drawable/btn1" />
<ImageView
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btn2" />
</RelativeLayout>
最佳答案
您可以通过将边距设置为负值来实现。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView android:id="@+id/btn1"
android:layout_width="100dp"
android:layout_height="50dp"/>
<ImageView android:layout_width="100dp"
android:layout_height="50dp"
android:layout_toRightOf="@id/btn1"
android:layout_marginLeft="-20dp"/>
</RelativeLayout>
关于android - 将一个按钮重叠在另一个按钮上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16235144/