??????????????????????????? LinearLayoutControl is an important layout control in Android, a linear control, meaning that the contents of the control are only horizontally or vertically arranged. That is, in a straight line.
Controls can be controlled by their properties to control the position and size of controls within the control. The following are the 3 TreeView controls that were placed. The properties of this linearlayout control are arranged vertically.
????????
?? Here we see how the control is used by several properties of the control
??????? 1.Orientation Properties
???????????? This property sets the direction of control display within the LinearLayout? Vertical: Vertical Display??? Horizontal level Display
????????????? ? android:orientation= "Horizontal"
??????? 2. Gravity Properties
?????????? This property is used to set the control display position within the linearlayout. Android:gravity= "Center" indicates a vertical center display.
?????????? The attribute has the following enumeration values:
?????????? android:gravity= "Top"
?????????? android:gravity= "Bottom"
??????????? Android:gravity= "left"
???????????? Android:gravity= "Right"
??????????? Android:gravity= "Center_vertical"
??????????? Android:gravity= "Fill_vertical"
?????????? Android:gravity= "Fill_horizontal"
?????????? Android:gravity= "Center_horizontal"
?????????? Android:gravity= "Center_vertical"
???????? android:gravity= "Fill"
?????????? Android:gravity= "Clip_vertical"
??????????? Android:gravity= "Clip_horizontal"
????????
?????????? 3.layout_weight Property
??????????????????? Layout_weight is mainly the property of the LinearLayout control parts. Used to set the percentage of LinearLayout controls.
?????????????????? 3.1. When the controls within the LinearLayout are arranged vertically, and the TextView height android:layout_height= "wrap_content". We set one of the TextView android:layout_weight= "1",
????????????????????? Effects such as the following:
?????????????????????? ????????????????????????? Code????????????????????????
<?
XML version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/ Res/android "android:layout_width=" match_parent "android:layout_height=" match_parent "android:orientation=" vertic Al "> <textview android:id=" @+id/textview1 "android:layout_width=" Fill_parent "Android:la yout_height= "Wrap_content" android:text= "label 1" android:background= "#ff0000"/> <textview Android:id= "@+id/textview2" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "label 2" android:background= "#FFB5C5"/> <textview Android:id= "@+id/textview3" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:text= "Label 3" android:background= "#EE82EE"/></LINEARLAYOUT>
????????????????????????????????????????????? Here we analyze why this effect, first of all, we are proportional to the vertical control, three labels layout_height are wrap_content, when three labels by the height of the occupied space. The remaining space is allocated at layout_weight scale, because label 1 and label 3 do not have the Layoutweight property set. Defaults to 0, so the rest of the space is allocated to the label 2,???????????????????? Keep in mind that this time the TextView? android:layout_height= "Wrap_content"
???????????? ?????????????????? 3.2? When we put three TextViewandroid:layout_height= "Fill_parent", at the same time, the label 1 layout_weight set to 1, label 2 and label 3 of the Layout_weight set to 2,?????????? then we'll see different effects.?????????????????????????????????? code such as the following?????????????????
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" match_parent "android:orientation=" vertical " > <textview android:id= "@+id/textview1" android:layout_width= "Fill_parent" android:layout _height= "Fill_parent" android:text= "label 1" android:background= "#ff0000" android:layout_weight= "1" /> <textview android:id= "@+id/textview2" android:layout_width= "Fill_parent" Android:layo ut_height= "Fill_parent" android:layout_weight= "2" android:text= "label 2" android:background= "#FFB5C5" /> <textview android:id= "@+id/textview3" android:layout_width= "Fill_parent" Android:la yout_height= "Fill_parent" android:text= "label 3" android:background= "#EE82EE" android:layout_weight= " 2 "/></linearlayout>
????????????????? See this effect, you may feel puzzled, label 2 and label 3 's weight value is 2. The WEIGIHT value of label 1 is 1, why does the label 1 occupy a larger space? ?????????????????? At this point, because we set the property of the space to fill_parent after the layout_height= "Fill_parent", then the proportion of the control will be proportional to the control distribution,? The smaller the proportion, the greater the space????
???????????????? 4. Product List Demo Sample???????????????? Let's show a sample of a product list using LinearLayout, first create a raw directory under the Res directory in the project, then place the product picture in the raw directory, and then we start the layout, for example the following???????????????? ???????????????
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:orientation=" vertical "android:layout_width=" fill_parent "android:layout_height=" Fill_parent " android:gravity= "Top" > <linearlayout android:layout_width= "fill_parent" android:layout_height= "10DP" > </LinearLayout> <linearlayout android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:orientation= "Horizontal" android:gravity= "center" > <linearlayout android:layout_width= "Fill_pa Rent "android:layout_weight=" 2 "android:orientation=" vertical "android:layout_height=" fill_parent "> <Image View android:id= "@+id/imageview1" android:layout_width= "90DP" android:layout_height= "90DP "Android:src=" @raw/pad "/> </LinearLayout> <linearlayout android:layout_width=" Fill_pa Rent "android:layout_weight=" 1 "Android:orientation= "vertical" android:layout_height= "fill_parent" > <textview android:id= "@+id/ TextView1 "android:layout_width=" wrap_content "android:layout_height=" Wrap_content " android:text= "Product Name: IPAD Air" android:layout_weight= "1"/> <textview Android:id= "@+id/textview2" android:layout_width= "Wrap_content" Android:layo ut_height= "Wrap_content" android:layout_weight= "1" android:text= "Product Price: $"/> <textview android:id= "@+id/textview3" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "Product color: White"/> ; </LinearLayout> </LinearLayout> <linearlayout android:layout_width= "Fill_parent" a Ndroid:layout_height= "2DP" android:background= "#F0F0F0" > </LinearLayout> <linearlayout android:layout_width= "fill _parent "android:layout_height=" wrap_content "android:orientation=" horizontal "android:gravity=" center > <linearlayout android:layout_width= "Fill_parent" android:layout_weight= "2" android:orientation= "vertical" android:layout_height= "Fill_parent" > <imageview android:id= "@+id/imageview1" Android:la Yout_width= "90DP" android:layout_height= "90DP" android:src= "@raw/pad"/> </LinearLayout> <linearlayout android:layout_width= "Fill_parent" android:layout_weight= "1" android:orientation= "vertical" android:layout_height= "Fill_parent" > <textview android:id= "@+id/textview1" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Product Name: IPAD Air "Android:layout_weight= "1"/> <textview android:id= "@+id/textview2" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_we ight= "1" android:text= "commodity price: $/> <textview android:id=" @+id/textview3 " Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android oid:layout_weight= "1" android:text= "Product color: White"/> </LinearLayout> </linear layout> <linearlayout android:layout_width= "fill_parent" android:layout_height= "2DP" android:background= "#F0F0F0" > </LinearLayout> <linearlayout android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:orientation= "horizontal" android:gravity= "center" > <linearlayout android:layou T_width= "Fill_parent" android:layout_weight= "2" android:orientation= "vertical" android:layout_height= "fill_parent" > <imageview Android:id= "@+id/imageview1" android:layout_width= "90DP" android:layout_height= "90DP" android:src= "@raw/pad"/> </LinearLayout> <linearlayout android:layout_width= "Fill_parent" a ndroid:layout_weight= "1" android:orientation= "vertical" android:layout_height= "fill_parent" > <textview Android:id= "@+id/textview1" android:layout_width= "Wrap_content" android:layou t_height= "Wrap_content" android:text= "Product Name: IPAD Air" android:layout_weight= "1" /> <textview android:id= "@+id/textview2" android:layout_width= "Wrap_cont Ent "android:layout_height=" wrap_content "android:layout_weight=" 1 "android: text= "Product Price: $/>" <textview android:id= "@+id/textview3" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "Product color: White "/> </LinearLayout> </LinearLayout> </LinearLayout>
????
. NET Program Ape play turn Android Development---(6) Linear layout LinearLayout