The function of the project is to achieve LinearLayout
The following code is the code in Mainactivity.java
Packagecom.example.linearlayout;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.view.Menu;ImportAndroid.view.MenuItem;ImportAndroid.widget.TextView; Public classMainactivityextendsActivity {PrivateTextView Firsttext; PrivateTextView Secondtext; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Firsttext=(TextView) Findviewbyid (R.id.firsttext); Secondtext=(TextView) Findviewbyid (R.id.secondtext); Firsttext.settext (R.string.firsttext); Secondtext.settext (R.string.secondtext); }}
The following code is the code in Activity_main.xml
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:id= "@+id/linearlayout1"Android:layout_width= "Fill_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical"Tools:context= "${relativepackage}.${activityclass}" ><!--android:id the corresponding ID for the control android:text the text displayed in the specified control android:gravity the base of the specified control This location/Center Right, etc. android:textsize the base position of the specified control/Center Right android:background specifies the background color used by the control, and the RGB nomenclature android:width the width of the specified control Android:height Specifies the height of the control android:padding the padding of the specified control android:weight the number to the corresponding proportional android:singleline setting Tru E is displayed for the same line-<TextView Android:id= "@+id/firsttext"android:gravity= "Center_vertical"android:textsize= "20pt"Android:background= "#0000ff"Android:layout_width= "Fill_parent"Android:layout_height= "0.0dip"Android:paddingleft= "10dip"Android:paddingtop= "20dip"Android:paddingright= "30dip"Android:paddingbottom= "40dip"Android:layout_weight= "1"Android:singleline= "true"/> <TextView Android:id= "@+id/secondtext"android:gravity= "Center_vertical"android:textsize= "15pt"Android:background= "#00ff00"Android:layout_width= "Fill_parent"Android:layout_height= "0.0dip"Android:paddingleft= "10dip"Android:paddingtop= "20dip"Android:paddingright= "30dip"Android:paddingbottom= "40dip"Android:layout_weight= "2"Android:singleline= "true"/></linearlayout>
The following code is the code in String.xml
<?xml version= "1.0" encoding= "Utf-8"?><resources> <string name= "App_name" >linearlayout</ string> <string name= "Hello_world" >hello world!</string> <string name= "FirstText" > First line </string> <string name= "Secondtext" > Second row </string></resources>
Android Learning Note--linearlayout