|--按钮1--|
|-按钮2-|
使用 RelativeLayout 如何对齐按钮 2 的宽度以匹配按钮 1 的宽度。
|--按钮1--|
|-按钮2-|
使用 RelativeLayout 如何对齐按钮 2 的宽度以匹配按钮 1 的宽度。
<Button
android:id="@+id/A"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="40dip"
android:textSize="14sp"
android:text="--Button1--" />
<Button
android:id="@+id/B"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/A"
android:gravity="center"
android:text="Button2"
android:layout_alignLeft="@id/A"
android:layout_alignRight="@id/A"
android:textSize="14sp" />
在你的里面试试上面的RelativeLayout
您正在寻找的应该是layout_alignRight。这会将您View
的右边缘与给定锚的右边缘对齐。
如果您希望 Button 2 依赖于 Button 1,那么(据我所知)没有办法这样做。但是,如果您正在设计动态布局,则可以通过编程方式进行。