Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does android:layout_weight mean?

I don't understand how to use this attribute. Can anyone tell me more about it?

like image 845
Mojiiz Avatar asked Oct 22 '10 10:10

Mojiiz


People also ask

What is the use of layout_weight in android?

LinearLayout also supports assigning a weight to individual children with the android:layout_weight attribute. This attribute assigns an "importance" value to a view in terms of how much space it should occupy on the screen. A larger weight value allows it to expand to fill any remaining space in the parent view.

What is layout_weight and weightSum in android?

Answer: Per documentation, android:weightSum defines the maximum weight sum, and is calculated as the sum of the layout_weight of all the children if not specified explicitly. Let's consider an example with a LinearLayout with horizontal orientation and 3 ImageViews inside it.

What is the meaning of Wrap_content in android?

WRAP_CONTENT means that the view wants to be just large enough to fit its own internal content, taking its own padding into account.

What is android gravity?

android:gravity is used to specify how to place the content of the object within the object itself. In another word, android:gravity is used to specify the gravity of the content of the view. android:layout_gravity is an attribution the child can supply to its parent, to specify the gravity the view within its parents.


1 Answers

With layout_weight you can specify a size ratio between multiple views. E.g. you have a MapView and a table which should show some additional information to the map. The map should use 3/4 of the screen and table should use 1/4 of the screen. Then you will set the layout_weight of the map to 3 and the layout_weight of the table to 1.

To get it work you also have to set the height or width (depending on your orientation) to 0px.

like image 115
Flo Avatar answered Oct 11 '22 21:10

Flo