ultimatenirvana
ultimatenirvana

Reputation: 451

Android: How to Distribut Weight Evenly

I want to create an android activity that looks like the one below this. This one has 4 layouts and one has a scroll view. When I add layouts, they get put on the bottom of each other or off the screen. How can I make them fit on one screen.

enter image description here

Upvotes: 1

Views: 1773

Answers (1)

mxk
mxk

Reputation: 43544

The layout parameters for LinearLayout can take a weight attribute that you can use to divide space in a relative fashion among its child views. If, for instance, you want to give two buttons in a LinearLayout the same space, you can set the layout weight on both to the same non-zero numeric value (doesn't matter what the value is as long as its equal, i.e. 0.5/0.5 will do just as 1/1):

<LinearLayout ...>
    <Button android:layout_weight="1" ... />
    <Button android:layout_weight="1" ... />
</LinearLayout>

Don't forget to set the dimension of the axis along which you want the view to grow to 0, i.e. if you want to stretch horizontally, set android:layout_width="0px".

Upvotes: 5

Related Questions