I don\'t understand how to use this attribute. Can anyone tell me more about it?
Think it that way, will be simpler
If you have 3 buttons and their weights are 1,3,1 accordingly, it will work like table in HTML
Provide 5 portions for that line: 1 portion for button 1, 3 portion for button 2 and 1 portion for button 1
Regard,
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.
For additional:
For vertical
orientation, don't forget set height
to 0dp
android:layout_height="0dp"
For horizontal
orientation, don't forget set width
to 0dp
android:layout_width="0dp"
one of the best explanations for me was this one (from the Android tutorial, look for step 7):
layout_weight is used in LinearLayouts to assign "importance" to Views within the layout. All Views have a default layout_weight of zero, meaning they take up only as much room on the screen as they need to be displayed. Assigning a value higher than zero will split up the rest of the available space in the parent View, according to the value of each View's layout_weight and its ratio to the overall layout_weight specified in the current layout for this and other View elements.
To give an example: let's say we have a text label and two text edit elements in a horizontal row. The label has no layout_weight specified, so it takes up the minimum space required to render. If the layout_weight of each of the two text edit elements is set to 1, the remaining width in the parent layout will be split equally between them (because we claim they are equally important). If the first one has a layout_weight of 1 and the second has a layout_weight of 2, then one third of the remaining space will be given to the first, and two thirds to the second (because we claim the second one is more important).
As the name suggests, Layout weight specifies what amount or percentage of space a particular field or widget should occupy the screen space.
If we specify weight in horizontal orientation, then we must specify layout_width = 0px
.
Similarly, If we specify weight in vertical orientation, then we must specify layout_height = 0px
.
Adding android:autoSizeTextType="uniform"
will resize the text for you automatically