This the code I have
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.75">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New "
android:id="@+id/button"
android:layout_weight="1"
android:background="#ffffffff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New "
android:id="@+id/button2"
android:layout_weight="1"
android:background="#ffffffff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New "
android:id="@+id/button3"
android:layout_weight="1"
android:background="#ffffffff" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New "
android:id="@+id/button5"
android:layout_weight="2"
android:background="#ffffffff" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New "
android:id="@+id/button7"
android:layout_weight="1"
android:background="#ffffffff" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:text="New "
android:id="@+id/button4"
android:background="#ffffffff" />
</LinearLayout>
And this is how it looks:
I want the first This's width be as the first two New and the second This's width be as the third New
So it looks like this:
The only way I can do that is by putting the weights on 0.93/0.07
Shouldn't it work with weights 2/1 as the code above is?
Try leaving out
android:weightSum="3"
for your second row of buttons. When you omit weightSum, the weights of the views are totaled by default and they essentially become straight proportions (ratios like 2 to 1). So, just using weight=2 for first button (id button5), then weight=1 for second button (id button7) should work.Also, when using
layout_weight
, make sure that your resizable views havelayout_width
orlayout_height
equal to zero.Try this xml: