Android Learning Note--linearlayout

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.