Android UI Control Series: TextView (text box)

Source: Internet
Author: User
TextView is relatively simple and can not be used for editing, only to display information

Some common XML attributes in the layout file

Android:gravity-used to set the alignment of text within a control

Android:layout_gravity-is used to set the alignment of a control relative to the parent control

Android:text-used to set control text information

Android:layout_width-used to set the width of the control

Android:layout_height-used to set the height of the control

Android:background-used to set the background color of the control

android:textcolor-to set the color of text within a control

Android:textsize-used to set the text font size of the control

Android:width and android:height-functions are similar to Android:layout_width

Difference:

Android:layout_width can only set fill_parent (fill the entire screen horizontally) or
Wrap_content (the size of the control itself is filled horizontally)

Android:width Setting the horizontal size unit of a specific control is pixel
Example: TextView display

Main.xml Layout file

<?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"      >  <textview      android:layout_width= "fill_parent"      android:layout_ height= "Wrap_content"      android:text= "@string/hello"      />  </LinearLayout>

String.xml file

<?xml version= "1.0" encoding= "Utf-8"?>  <resources>      <string name= "Hello" >hello world, mytestview!</string>      <string name= "app_name" >MyTestView</string>  </resources>

Mytextview.java file

Package Org.loulijun.MyTestView;    Import android.app.Activity;  Import Android.os.Bundle;    public class Mytestview extends activity {      /** called when the activity is first created. */      @Override      Public void OnCreate (Bundle savedinstancestate) {          super.oncreate (savedinstancestate);          Setcontentview (R.layout.main);      }  }

Operation Result:

The above is the Android UI Control series: TextView (text box) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • 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.