Linear Layout as the name is suggesting us that it aligns the views in linear fashion. This layout aligns its children in either direction such as horizontal or vertical. You can set the direction (horizontal or vertical) of layout by using
android:orientation
attribute. Let us see diagrammatically how linear layout align its children : view 1 | view 2 | view 3 | view 4 |
Fig 0.1 Orientation : Horizontal
view 1view 2 view 3 view 4
Fig 0.2 Orientation : Vertical
Now let us see some attributes of linear layout :
It will arrange the children in either horizontal or vertical direction.
It will position the child in center or top or left or right or topleft(top|left) or topright(top|right) etc.
It defines in how many section or division will linear layout be divided. It affects the value of
android:layout_weight. Following example will explain it how :
if linear layout has given weightSum of 3 , it means it should be divided in three sections,
if linear layout has given weightSum of 3 , it means it should be divided in three sections,
now if linear layout has three child such as 3 textviews then if their layout_weight is 1 for
each then all textviews will be divided into equal sections.
if one of the textview's layout_weight is 2 then it will have twice the section then other two textviews.
if one of the textview's layout_weight is 2 then it will have twice the section then other two textviews.
It is not compulsory to provide weightSum to the linear layout. But if you provide layout_weight to its children
they will work accordingly.
No comments:
Post a Comment