Android Studio 文本控件TextView

功能

用於在界面上顯示文本信息。

簡單實例

顯示簡單的幾個文本內容。

<?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>

效果:
在這裏插入圖片描述

文本顯示在同一行

正常情況下,當文本很多時,會自動換行。爲了節省空間,可以設置文本顯示在同一行,當超過屏幕寬度時滾動顯示。代碼:

<?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>

效果
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章