Android tablet weight does not work as I thought

after What does android mean: layout_weight?

I have it:

<LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent" android:orientation="horizontal" > <Button android:id="@+id/buttonToastSimple" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="English Toast" /> <Button android:id="@+id/buttonToastFancy" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="3" android:text="French Toast" /> </LinearLayout> 

The link tells me that buttonToastFancy will take three quarters of the size (3 / (3 + 1), but vice versa. The ToastSimple button takes three quarters of the screen size according to Eclipse / my AVD.

What am I doing wrong?

+8
android layout
source share
2 answers
 <LinearLayout android:layout_width="match_parent" android:layout_height="fill_parent" android:weightSum="4" android:orientation="horizontal" > <Button android:id="@+id/buttonToastSimple" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="English Toast" /> <Button android:id="@+id/buttonToastFancy" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:text="French Toast" /> </LinearLayout> 

try setting the desired 0dp attribute ..

ex. if you set the weight to support the width, use android:layout_width="0dp" along with android:layout_weight="3" . Also, don't forget android:weightSum="4" in the parent.

+24
source share

the amount of space that your view will take is calculated as size / layout_weight, so a view with a lower layout_weight takes up more space in your layout. in the future, you may also need the user layout_weightSum.

They are further explained here .

0
source share

All Articles