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>

原文地址:https://www.cnblogs.com/my-love-is-python/p/14515139.html