LinearLayout is also a sub-class of ViewGroup, which is considered a container.
Two most important XML attributes: Android:layout_gravity android:gravity
There is also a property, is the two goods of the ye. Android:orientation.
Here's the discussion.
1:<linearlayout android:layout_width= "fill_parent" android:layout_height= "100DP" android:orientation= "vertical ">
When the layout direction is perpendicular. Define the sons, and you must be in a vertical line. And in order, don't cut the queue ....
Android:gravity the goods can also call his father Gravity. Devoted to the control of his son. Control the gravity of the son.
For example, I want to have a row of sons on the left, on the right, in ... One for 9 positions,,,, I'm not wrong about it.
Android:layout_gravity the goods are the control of each son's own gravity.
Paralysis, android:gravity not want us to line up in a row, neat rows. I would not,
<linearlayout android:layout_width= "fill_parent" android:layout_height= "Fill_parent" android: gravity= "center" android:orientation= "vertical" > <textview android:layout_width= "Wrap_ Content " android:layout_height=" wrap_content " android:layout_gravity=" left " android:text=" Nihao "/ > <textview android:layout_width= "wrap_content" android:layout_height= "Wrap_content " android:text= "Nihao"/> <textview android:layout_width= "wrap_content" android:layout_ height= "Wrap_content" android:text= "Nihao"/> <textview android:layout_width= "wrap_content " android:layout_height=" wrap_content " android:text=" Nihao "/> </LinearLayout>
The goods went to the left. It's a thought, isn't it? Our sons are not still in the middle of the vertical direction. No, I'm going to the upper left corner. Good |top. It turns out. Still the same in the left.
That is, Dad's gravity to limit a group of sons to these 9 positions ... If a son does not obey. Want to run. Or you can. Their big Uncle limited the orientation to death ... Son, you want to run. Can only run in the direction orientation not set .... In my case, I can only run in the horizontal direction.
and a word. Is that dad didn't set android:gravity. What to do. Well done. Go straight to the upper left corner. Press a row.
However, this can not completely meet my needs ah. Sometimes I don't want to be in a row. How to pinch ...
All right, android:weightsum and Android:layout_weight.
The first one is defined by dad. My possessions (space) are all these. What is the meaning of wrap_content, is the son enough to eat (space).
The second is how much wealth the son can divide (space), if he is nearly wrap_content. It's okay. The first to occupy.
<linearlayout android:layout_width= "fill_parent" android:layout_height= "Fill_parent" Android:gravi ty= "center" android:orientation= "vertical" android:weightsum= "5" > <textview Android : layout_width= "wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "left" android:text= "Nihao1"/> <textview android:layout_width= "Wrap_content" android:l ayout_height= "Wrap_content" android:layout_gravity= "Left|top" android:text= "Nihao2"/> < ; TextView android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android : layout_weight= "1" android:text= "Nihao3"/> <textview android:layout_width= "Wrap_conten T "android:layout_height=" wrap_content "android:text=" Nihao4 "/> </LinearLayout>
Android's LinearLayout