Android基礎-TextView(文本控件)


TextView主要用於文本顯示

 屬性

    1.android:textSize="22sp" 設置文本字體

    2.android:textColor="#00ffff" 設置文本顏色

    3.android:lineSpacingExtra="15sp" 設置文本的間距 

    4.android:lineSpacingMultiplier="2" 設置文本的倍距

    5.android:text="@string/long_text" 設置文本內容

    6.android:singleLine="true" 設置單行 android:lines="1" 也是設置單行

    7.android:ellipsize="start" 將省略號設置在前面 ="end" 將省略號設置在后面 

    8.android:focusable="true" 設置可以獲取屏幕的焦點 

    9.android:focusableInTouchMode="true" 設置觸摸時可以獲取屏幕的焦點 

    10.android:marqueeRepeatLimit = "marquee_forever" 跑馬燈的次數為無限次

1.Text 示例1

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TextActivity">

    <!--android:textSize="22sp" 設置字體大小
    android:textColor="#00ffff" 設置字體顏色
    android:lineSpacingMultiplier="2" 倍距
    android:lineSpacingExtra="15sp"

    -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:textSize="22sp"
        android:textColor="#00ffff"
        android:lineSpacingExtra="15sp"
        android:text="@string/long_txt"/>


</ScrollView>

 

 

 

Text 示例2

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".TextActivity">

    <!--android:focusable="true" 設置可以獲得屏幕的焦點
    android:focusableInTouchMode="true"  設置觸摸時可以獲取屏幕的焦點
    android:marqueeRepeatLimit="marquee_forever" 跑馬燈的次數為無限次

    -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:singleLine="true"
        android:text="@string/long_txt" />


</ScrollView>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM