Reputation: 976
I have a problem with my xml file. I have two buttons with custom size. I would like to resize buttons to the similar size in relation to the screens.
On the picture 1 you can see how big they should be.
On the picture 2 you can see that they are too far away and small.
I know that I didn't set it correct. (mainly android:layout_width) But how to set that?
Here is my xml code:
<Button
android:id="@+id/button2"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#99000099" />
<Button
android:id="@+id/button1"
android:layout_width="130dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#99990000" />
Thanks for reply! :)
Upvotes: 1
Views: 2383
Reputation: 4314
If you try to use a LinearLayout
to wrap the buttons, you can put that at the bottom and then set the weights of the buttons to 1 each, which means they'll take up half the screen each.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true">
<Button
android:id="@+id/button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#99000099" />
<Button
android:id="@+id/button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#99990000" />
</LinearLayout>
Note that you can change the margins on the buttons in order to space them apart and away from the edges too, like your first picture.
Upvotes: 4