![](/img/trans.png)
[英]How to set all elements of linear layout to be same width in android?
[英]Android: how to set two buttons in vertical linear layout to same width?
在我的Android应用程序中,我想创建一个对话框窗口,该窗口顶部包含一个图像,中间包含一些信息文本,下面包含两个按钮。 这两个按钮位于垂直方向的线性布局中。 两者的宽度相同。
我设法创建了与上述类似的布局,但是,上面带有较长文本的按钮变得比另一个宽。 在附图中,下方的按钮比上方的按钮稍宽,如红色虚线所示。
我用于此内部线性布局的布局如下所示:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:id="@+id/close_dialog_button_ok"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/upload_dialog_ok"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip" />
<Button
android:id="@+id/close_dialog_button_cancel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/upload_dialog_cancel"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:layout_marginBottom="5dip" />
</LinearLayout>
有什么想法我在这里做错了吗?
在此先感谢您的帮助!
您忘记在第二个按钮上设置android:layout_marginLeft="10dip"
如果您希望它们相同,则必须将'android:layout_width =“ fill_parent”'更改为类似于'200dp'的名称。 由于其中的文本较长,因此该应用将使其中一个较长。 因此,尝试将两个按钮都设置为此:
android:layout_width="200dp"
它们将是相同的,并且由于使用了'dps',因此在所有屏幕尺寸上都应正确保持比例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.