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)!