1. 功能
用于在界面上顯示文本資訊。
2. 簡單執行個體
顯示簡單的幾個文本内容。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="你好"
android:textColor="#000000"
android:textSize="24sp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:text="你是誰"
android:textColor="#6AC522"
android:textSize="24sp"/>
</LinearLayout>

3. 文本顯示在同一行
正常情況下,當文本很多時,會自動換行。為了節省空間,可以設定文本顯示在同一行,當超過螢幕寬度時滾動顯示。代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="你好1234567890123456789012345678901234567890"
android:textColor="#000000"
android:textSize="24sp"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"/>
</LinearLayout>