textView 跑马灯效果

本文详细介绍Android中TextView控件的高级用法,包括设置跑马灯效果、处理HTML文本、自动链接电话号码和网址,以及使用自定义样式。通过具体代码示例,读者将学会如何在Android应用程序中更灵活地展示文本。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="utf-8"?>

<!--
    android:lines=""        设置行数
    android:single="true"   设置单行
    android:ellipsize=""    设置省略号
    android:focusable="true" 设置可以获取焦点
    android:focusableInTouchMode="true"设置在触摸时获取焦点
    android:marqueeRepeatLimit="marquee_forever" 设置跑马灯持续运行

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

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="含html标签的文本"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="10dp"
    android:background="#cccccc"/>

<TextView
    android:id="@+id/html_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="带链接动作、自定义样式的文本"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="10dp"
    android:background="#cccccc"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="13977889900"
    android:autoLink="phone"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="www.baidu.com"
    android:autoLink="web"/>

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="13977889900\nwww.baidu.com"
    android:autoLink="all"/>
<!--
    android:id=""
    @+id/xx     为控件指定id
    @id/xx      引用一个id(相对布局)
-->
<TextView
    android:id="@+id/auto_link_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/move_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<TextView
    android:id="@+id/style_txt"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值