ssummeraw 2013-07-01 05:09 采纳率: 10%
浏览 7128

在layout中让按钮有相同的宽度

我在一个relative layout 中设置了4个按钮。我想把按钮设置成相同的宽度,以遍适应一个手机的任何屏幕大小。
代码如下:

<RelativeLayout
            android:id="@+id/relativeLayout1"
            android:layout_width="match_parent"
            android:layout_height="38dp" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:text="Button" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/button1"
                android:text="Button" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/button2"
                android:text="Button" />

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/button3"
                android:text="Button" />

        </RelativeLayout>

要如何修改?

  • 写回答

1条回答 默认 最新

  • 码密码密哄 2013-07-01 05:40
    关注

    可以不使用RelativeLayout吗?不行的话你就在这布局外面套一个RelativeLayout

    <LinearLayout
                android:id="@+id/relativeLayout1"
                android:layout_width="match_parent"
                android:layout_height="38dp"
                android:weightSum="4" >
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight = "1"
                    android:text="Button" />
    
                <Button
                    android:id="@+id/button2"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight = "1"
                    android:text="Button" />
    
                <Button
                    android:id="@+id/button3"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight = "1"
                    android:text="Button" />
    
                <Button
                    android:id="@+id/button4"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight = "1"
                    android:text="Button" />
    
            </LinearLayout>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误