开发者

How to make button share half the width of a dialog in android?

开发者 https://www.devze.com 2023-04-13 04:44 出处:网络
i want to make the buttons take up half the width of the dialog each, thanks x3. <RelativeLayout android:layout_width=\"fill_parent\"

i want to make the buttons take up half the width of the dialog each, thanks x3.

How to make button share half the width of a dialog in android?

<RelativeLayout android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:paddingBottom="10dp"
    android:paddingLeft="10dp" android:paddingRight="10dp">
    <TextView android:layout_width="fill_parent"
        android:layout_height="1dip" android:background="#FFFFFF" android:id="@+id/seperator_line" />
    <TextView android:layout_width="wrap_content"
      开发者_运维百科  android:layout_height="wrap_content" android:id="@+id/text1"
        android:text="Amount:" android:textColor="#FFFFFF"
        android:layout_below="@id/seperator_line" android:padding="10dp" />
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/deleteButton_dialog"
        android:layout_below="@id/text1" android:text="Delete" />
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/cancelButton_dialog"
        android:text="Cancel" android:layout_toRightOf="@id/deleteButton_dialog"
        android:layout_below="@id/text1" />
</RelativeLayout>


You can place them in a LinearLayout and then set the width to "fill_parent" and the layout_weight to "1". Like this:

<LinearLayout android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:orientation="horizontal"
              android:layout_below="@id/text1">
    <Button android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/deleteButton_dialog"
            android:text="Delete" />
    <Button android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:id="@+id/cancelButton_dialog"
            android:text="Cancel"/>
</LinearLayout>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号