LinearLayout is a viewgroup that displays the view element in a linear direction, either horizontally or vertically
You can reuse linearlayout, and if you want to use nested multi-layered linearlayout, you can consider using Relativelayout instead.
1. Start creating an engineering name called Hellolinearlayout.
2. Open the Res/layout/main.xml file and insert 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 " > <linearlayout android:orientation= "Horizontal" android:layout_width= "Fill_pa Rent "android:layout_height=" fill_parent "android:layout_weight=" 1 "> <t Extview android:text= "Red" android:gravity= "Center_horizontal" Android:background= "#aa0000" android:layout_width= "Wrap_content" a ndroid:layout_height= "Fill_parent" android:layout_weight= "1"/> &L T TextView android:text= "Green" android:gravity= "Center_horizontal" Android:background= "#00aa00 "android:layout_width=" wrap_content "android:layout_height=" Fill_par Ent "android:layout_weight=" 1 "/> <textview android:text= "Blue" android:gravity= "Center_horizontal" Android:backgrou Nd= "#0000aa" android:layout_width= "wrap_content" android:layout_height= "fill _parent "android:layout_weight=" 1 "/> <textview android:text= "Yellow" android:gravity= "Center_horizontal" Android:ba Ckground= "#aaaa00" android:layout_width= "Wrap_content" android:layout_height = "Fill_parent" android:layout_weight= "1"/> </LinearLayout> & Lt LinearLayout android:orientation= "vertical" android:layout_width= "fill_parent" Android:layout_heig ht= "Fill_parent" android:layout_weight= "1" > <textview android:t ext= "Row One" android:textsize= "15pt" android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/ > <textview android:text= "Row" android:textsize= "15 PT "Android:layout_width=" Fill_parent "android:layout_height=" Wrap_content " android:layout_weight= "1"/> <textview A ndroid:text= "Row three" android:textsize= "15pt" android:layout_width= "fill_p Arent " android:layout_height= "Wrap_content" android:layout_weight= "1"/> <textview android:text= "Row Four" android:textsize= "15pt" Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1"/> </LinearLayout></LinearLayout>
Double-check the XML file. There is a root element linearlayout defines that its direction is vertical, all sub-view (total 2) is stacked vertically, the first child is another horizontal layout of the LinearLayout, And the second child is a vertically-oriented linearlayout, each of these nested linearlayout contains several textview elements whose orientation is defined by the parent linearlayout tag.
3. Now open Hellolinearlayout.java and make sure it has loaded the Res/layout/main.xml layout file in the OnCreate () method
public void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (R.layout.main);
The Setcontentview (int) method loads the layout file for activity, which is specified by the resource resource ID-r.layout.main refers to the Res/layout/main.xml layout file
4, run the program, you can see the following conditions
The above is the Android UI control family: LinearLayout (linear layout) content, more about the content please pay attention to topic.alibabacloud.com (www.php.cn)!