4

|--按钮1--|

|-按钮2-|

使用 RelativeLayout 如何对齐按钮 2 的宽度以匹配按钮 1 的宽度。

4

3 回答 3

5
<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

于 2010-12-02T10:50:24.077 回答
1

您正在寻找的应该是layout_alignRight。这会将您View的右边缘与给定锚的右边缘对齐。

于 2010-12-02T10:44:53.253 回答
-1

如果您希望 Button 2 依赖于 Button 1,那么(据我所知)没有办法这样做。但是,如果您正在设计动态布局,则可以通过编程方式进行。

于 2010-12-02T10:42:18.307 回答