[英]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.