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>

效果
在这里插入图片描述

发布了414 篇原创文章 · 获赞 287 · 访问量 57万+

猜你喜欢

转载自blog.csdn.net/woshisangsang/article/details/105192647