Reputation: 10369
In my Android app I want to create a dialog window that contains an image on top, some info text in the middle, and two buttons below. These two buttons are within a linear layout with vertical orientation. Both sould be of the same width.
I have managed to create a similar layout as described, however, the button with the longer text on it becomes wider than the other one. In the attached picture, the lower button is a bit wider than the button above, as marked by the dotted red line.
The layout I use for this inner linear layout looks as follows:
<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>
Any ideas what I am doing wrong here?
Thanks in advance for your help!
Upvotes: 0
Views: 2273
Reputation: 12335
You will have to change the 'android:layout_width="fill_parent"' to something like '200dp' if you want them to be the same. As the app will make one of them longer due to the text inside being longer. So try setting both buttons to this:
android:layout_width="200dp"
They will then be the same and due to using 'dps', should still stay in proportion correctly on all screen sizes.
Upvotes: 0
Reputation: 445
You forgot to set android:layout_marginLeft="10dip"
on the second button
Upvotes: 3