I. Basic Knowledge:
Id = "@ + id/edtInput", which is a bridge between the UI and code
Layout_width = "fill_parent", automatically filled to the screen width
Layout_width = "wrap_content", automatically filled into the control size
Controls in LinearLayout are arranged horizontally or vertically:
Orientation = "horizontal": horizontal arrangement;
Orientation = "vertical": vertical arrangement
Use android: layout_weight to specify the percentage (weight ).
In the case of nested LinearLayout, The sublinearlayout must be set with the permission value. Otherwise, the default situation is that the sublinearlayout without the permission value occupies the entire screen.
Android: id -- specify the corresponding ID for the control
Android: text -- specify the text displayed in the control. Note that strings in the strings. xml file should be used as much as possible here.
Android: grimace -- specifies the basic position of the control, such as center and right.
Android: textSize -- specifies the font size in the control.
Android: background -- specifies the background color used by the control. The RGB naming method is used.
Android: width -- specify the width of the control
Android: height -- specify the height of the control
Android: padding * -- specifies the padding of the control, that is, the content in the control.
Android: sigleLine -- if set to true, the control content is displayed in the same row.
Ii. Code display:
1. "Acticity_05srcyanacticity_05MainActivity.java"
[Java]
Package yan. acticity_05;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. Menu;
Public class MainActivity extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
}
Package yan. acticity_05;
Import android. OS. Bundle;
Import android. app. Activity;
Import android. view. Menu;
Public class MainActivity extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
}
@ Override
Public boolean onCreateOptionsMenu (Menu menu ){
// Inflate the menu; this adds items to the action bar if it is present.
GetMenuInflater (). inflate (R. menu. activity_main, menu );
Return true;
}
}
2. "Acticity_05reslayoutactivity_main.xml"
[Html]
<? 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"
>
<! --
Code editing prompt shortcut: Alt +/
Id = "@ + id/edtInput", which is a bridge between the UI and code
Layout_width = "fill_parent", automatically filled to the screen width
Layout_width = "wrap_content", automatically filled into the control size
Controls in LinearLayout are arranged horizontally or vertically:
Orientation = "horizontal": horizontal arrangement;
Orientation = "vertical": vertical arrangement
Android: id -- specify the corresponding ID for the control
Android: text -- specify the text displayed in the control. Note that strings in the strings. xml file should be used as much as possible here.
Android: grimace -- specifies the basic position of the control, such as center and right.
Android: textSize -- specifies the font size in the control.
Android: background -- specifies the background color used by the control. The RGB naming method is used.
Android: width -- specify the width of the control
Android: height -- specify the height of the control
Android: padding * -- specifies the padding of the control, that is, the content in the control.
Android: sigleLine -- if set to true, the control content is displayed in the same row.
-->
<EditText
Android: id = "@ + id/edtInput"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ + string/hello_world"
/>
<Button
Android: id = "@ + id/myButton"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<TextView
Android: id = "@ + id/firstText"
Android: text = "TextView first line"
Android: gravity = "center_vertical"
Android: textSize = "15pt"
Android: background = "# aa0000"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "10000"
Android: singleLine = "true"/>
<TextView
Android: id = "@ + id/secondText"
Android: text = "TextView Row 2"
Android: gravity = "center_vertical"
Android: textSize = "15pt"
Android: background = "# tianaa"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"/>
</LinearLayout>
<? 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"
>
<! --
Code editing prompt shortcut: Alt +/
Id = "@ + id/edtInput", which is a bridge between the UI and code
Layout_width = "fill_parent", automatically filled to the screen width
Layout_width = "wrap_content", automatically filled into the control size
Controls in LinearLayout are arranged horizontally or vertically:
Orientation = "horizontal": horizontal arrangement;
Orientation = "vertical": vertical arrangement
Android: id -- specify the corresponding ID for the control
Android: text -- specify the text displayed in the control. Note that strings in the strings. xml file should be used as much as possible here.
Android: grimace -- specifies the basic position of the control, such as center and right.
Android: textSize -- specifies the font size in the control.
Android: background -- specifies the background color used by the control. The RGB naming method is used.
Android: width -- specify the width of the control
Android: height -- specify the height of the control
Android: padding * -- specifies the padding of the control, that is, the content in the control.
Android: sigleLine -- if set to true, the control content is displayed in the same row.
-->
<EditText
Android: id = "@ + id/edtInput"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ + string/hello_world"
/>
<Button
Android: id = "@ + id/myButton"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
/>
<TextView
Android: id = "@ + id/firstText"
Android: text = "TextView first line"
Android: gravity = "center_vertical"
Android: textSize = "15pt"
Android: background = "# aa0000"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "10000"
Android: singleLine = "true"/>
<TextView
Android: id = "@ + id/secondText"
Android: text = "TextView Row 2"
Android: gravity = "center_vertical"
Android: textSize = "15pt"
Android: background = "# tianaa"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_weight = "1"/>
</LinearLayout>
Iii. effect display: