"Knowledge points"
Common layout methods in Android:
(1) Linear layout linearlayout: Layout components in a vertical or horizontal direction
(2) Frame layout framelayout: component from upper left corner of screen coordinate layout component
(3) Table layout tablelayout: Layout components by row and column
(4) Relative layout relativelayout: How to lay out relative to other components
(5) Absolute layout absolutelayout: Layout components according to absolute coordinates
1. Engineering Catalogue
2, Test_layout_activity.java
Package Com.example.test_layout;import Android.os.bundle;import Android.app.activity;import android.content.Intent ; Import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;public class Test_layout_activity extends Activity {private Button myButton1, MyButton2, MyButton3, MyButton4, myButton5; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.test__layout); myButton1 = (Button) Findviewbyid (r.id.buttonlayout01); MyButton2 = (Button) Findviewbyid (r.id.buttonlayout02); myButton3 = (Button) Findviewbyid (r.id.buttonlayout03); MyButton4 = (Button) Findviewbyid (r.id.buttonlayout04); myButton5 = (Button) Findviewbyid (r.id.buttonlayout05); Mybutton1.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubintent intent1 = new Intent (test_layout_activity.this,linearactivity.class); startactivity (intent1);}}); MybutTon2.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated method Stubintent Intent2 = new Intent (test_layout_activity.this,frameactivity.class); startactivity (Intent2);}}); Mybutton3.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubintent Intent3 = new Intent (test_layout_activity.this,tableactivity.class); startactivity (INTENT3);}}); Mybutton4.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubintent intent4 = new Intent (test_layout_activity.this,relativeactivity.class); startactivity (INTENT4);}}); Mybutton5.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {//TODO auto-generated Method Stubintent intent5 = new Intent (test_layout_activity.this,absoluteactivity.class); startactivity (INTENT5);}}); @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu;Adds items to the action bar if it is present.getmenuinflater (). Inflate (R.menu.test__layout_, menu); return true;}}
3, Linearactivity.java
Package Com.example.test_layout;import Android.app.activity;import Android.os.bundle;public class LinearActivity Extends activity{@Overrideprotected void OnCreate (Bundle savedinstancestate) {//TODO auto-generated method Stubsuper.oncreate (savedinstancestate); Setcontentview (r.layout.linear);}}
4, Frameactivity.java, Tableactivity.java, Relativeactivity.java, Absoluteactivity.java and Linearactivity.java are similar.
5, Test_layout.xml
<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" android:layout_width= "Match_parent" android:layout_height= "match_parent" android:orientation= "vertical" > <button android:id= "@+id/buttonLa yout01 "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" Linear Layout "/> <button android:id=" @+id/buttonlayout02 "android:layout_width=" Wrap_content "Android oid:layout_height= "Wrap_content" android:text= "Framelayout"/> <button android:id= "@+id/buttonLayou t03 "android:layout_width=" wrap_content "android:layout_height=" wrap_content "android:text=" TableLayo UT "/> <button android:id=" @+id/buttonlayout04 "android:layout_width=" Wrap_content "Android: layout_height= "Wrap_content" android:text= "Relativelayout"/> <button android:id= "@+id/buttonLayout "Android:layout_wiDth= "Wrap_content" android:layout_height= "wrap_content" android:text= "Absolutelayout"/></LinearLayout >
6, Linear.xml
<?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 " > <linearlayout android:layout_width= "fill_parent" android:layout_height= "Fill_parent" Andro id:layout_weight= "1" android:orientation= "horizontal" > <textview android:layout_width= "Wra P_content "android:layout_height=" Fill_parent "android:layout_weight=" 1 "Android:backgrou Nd= "#aa0000" android:gravity= "center_horizontal" android:text= "Red"/> <textview Android:layout_width= "Wrap_content" android:layout_height= "Fill_parent" android:layout_weight= " 1 "android:background=" #00aa00 "android:gravity=" center_horizontal "android:text=" green " /> <textview Android:layout_width= "Wrap_content" android:layout_height= "Fill_parent" android:layout_weight= "1" Android:background= "#0000aa" android:gravity= "center_horizontal" android:text= "Blue"/> ; <textview android:layout_width= "wrap_content" android:layout_height= "Fill_parent" Android oid:layout_weight= "1" android:background= "#aaaa00" android:gravity= "Center_horizontal" an droid:text= "Yellow"/> </LinearLayout> <linearlayout android:layout_width= "Fill_parent" an droid:layout_height= "Fill_parent" android:layout_weight= "1" android:orientation= "vertical" > <t Extview android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:l ayout_weight= "1" android:text= "Row_one" android:textsize= "15pt"/> <textview Android:layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_weight= "1" Andro id:text= "Row_two" android:textsize= "15pt"/> <textview android:layout_width= "Fill_paren T "android:layout_height=" Wrap_content "android:layout_weight=" 1 "android:text=" Row_three "Android:textsize=" 15pt "/> <textview android:layout_width=" Fill_parent "an droid:layout_height= "Wrap_content" android:layout_weight= "1" android:text= "Row_four" Android Oid:textsize= "15pt"/> </LinearLayout></LinearLayout>
7, Table.xml
<?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 " > <tablelayout android:id= "@+id/tablelayout01" android:layout_width= "Fill_parent" Android:la yout_height= "Wrap_content" android:collapsecolumns= "2" android:stretchcolumns= "1" > <tablerow Android:id= "@+id/tablerow01" android:layout_width= "wrap_content" android:layout_height= "WR Ap_content "> <textview android:id=" @+id/textview01 "android:layout_width=" Wrap_content "android:layout_height=" wrap_content "android:text=" user name "/> < EditText android:id= "@+id/edittext01" android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" android:text= "admin"/> </TableRow> <tablerow android:id= "@+id/tablerow "Android:layout_width=" wrap_content "android:layout_height=" wrap_content "> <tex TView android:id= "@+id/textview02" android:layout_width= "Wrap_content" Androi d:layout_height= "wrap_content" android:text= "User password"/> <edittext android:id= "@+id/edittext02" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:text= "123"/> </TableRow> <tablerow android:id= "@+id/tablerow02 "Android:layout_width=" wrap_content "android:layout_height=" wrap_content "> <butto n android:id= "@+id/button01" android:layout_width= "Wrap_content" Android:layo ut_height= "Wrap_content" android:text= "register"/> <button android:id= "@+id/button02" and Roid:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:text= "Login"/> ; </TableRow> </TableLayout></LinearLayout>
8, Frame.xml
<?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 " > <framelayout android:id= "@+id/framelayout01" android:layout_width= "Wrap_content" android:l ayout_height= "Wrap_content" > <textview android:id= "@+id/textview01" Android:layout_wid Th= "Wrap_content" android:layout_height= "wrap_content" android:background= "#aa0000" Andro id:height= "150px" android:width= "150px"/> <textview android:id= "@+id/textview02" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:background= "# 00aa00 "android:height=" 100px "android:width=" 100px "/> <textview android:id = "@+id/textview03" AndroId:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:background= "#0000aa" android:height= "80px" android:width= "80px"/> </FrameLayout></LinearLayout>
9, Relative.xml
<?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 " > <relativelayout android:id= "@+id/relativelayout01" android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" > <button android:id= "@+id/a" Android:layout_width= "W Rap_content "android:layout_height=" wrap_content "android:text=" A "/> <button Android:id= "@+id/b" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_torightof= "@id/A" android:text= "B"/> <button android:id= "@+id/c" Android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" Android:layout_b Elow= "@id/A" Android:text= "C"/> <button android:id= "@+id/d" android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" android:layout_below= "@id/b" android:layout_torightof= "@id/C" android:text= "D"/> </RelativeLayout></LinearLayout>
10, Absolute.xml
<?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 " > <absolutelayout android:id= "@+id/absolutelayout01" android:layout_width= "Wrap_content" and roid:layout_height= "Wrap_content" > <button android:id= "@+id/button01" Android:layout_w Idth= "Wrap_content" android:layout_height= "wrap_content" android:layout_x= "20px" Android: Layout_y= "20px" android:text= "A"/> <button android:id= "@+id/button02" Andro Id:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_x= "60px" Android:layout_y= "20px" android:text= "B"/> <button android:id= "@+id/button03" Android:layout_width= "Wrap_coNtent "android:layout_height=" wrap_content "android:layout_x=" 20px "android:layout_y=" 80p X "android:text=" C "/> <button android:id=" @+id/button04 "Android:layout_wid Th= "Wrap_content" android:layout_height= "wrap_content" android:layout_x= "60px" Android:la Yout_y= "80px" android:text= "D"/> </AbsoluteLayout></LinearLayout>
11, Androidmenifest.xml need to make some changes
<application android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@strin G/app_name "Android:theme=" @style/apptheme "> <activity android:name=" Com.example.test_layo Ut. Test_layout_activity "android:label=" @string/app_name "> <intent-filter> < Action android:name= "Android.intent.action.MAIN"/> <category android:name= "android.intent.category. LAUNCHER "/> </intent-filter> </activity> <activity android:name=" com.example.t Est_layout. Tableactivity "> </activity> <activity android:name=" Com.example.test_layout. Relativeactivity "> </activity> <activity android:name=" Com.example.test_layout. Frameactivity "> </activity> <activity android:name=" Com.example.test_layout. Absoluteactivity "> </activity> <activity android:name= "Com.example.test_layout. Linearactivity "> </activity> </application>
Android Application Development Details (vii)-------------------layout management layouts