TextView is relatively simple and cannot be used for editing. It can only be used to display information.
Some commonly used XML attributes in layout files
android:gravity—used to set the content of the control. Alignment of text
android:layout_gravity—used to set the alignment of the control relative to the parent control
android:text—used to set the text information of the control
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—used to set the color of the text in the control
android:textSize—used to set the text font size of the control
android:width and android:height—functions similar to android:layout_width
Difference:
android:layout_width can only set fill_parent (fill the entire screen horizontally) or
wrap_content (fill the size of the control itself horizontally)
android:width sets specific controls The horizontal size unit is pixels
For 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); } }
Running results:
The above is the content of the Android UI control series: TextView (text box). For more related content, please pay attention to PHP Chinese Net (www.php.cn)!