TextView 走马灯效果

本文详细介绍了如何在Android中使用TextView实现走马灯效果,包括关键代码配置及解决常见问题的步骤。

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

一般实现:

<TextView
             android:id="@+id/menu_desc"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:text="TextView 走马灯效果TextView 走马灯效果TextView 走马灯效果TextView 走马灯效果TextView 走马灯效果"
             android:singleLine="true"
             android:ellipsize="marquee"
             android:focusable="true"
             android:focusableInTouchMode="true"
             android:scrollHorizontally="true"
             android:marqueeRepeatLimit="marquee_forever"
             >
          </TextView>        

实际上就是加上了这5行代码:

             android:singleLine="true"
             android:ellipsize="marquee"
             android:focusable="true"
             android:focusableInTouchMode="true"
             android:scrollHorizontally="true"
             android:marqueeRepeatLimit="marquee_forever"

**

实现不了?

**
1、看看是不是有控件抢焦点了,比如EditText之类的,将他们的focusable设为false,android:focusable=”false”。比如说下面的:

 <EditText
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="@null"
                    android:textSize="13sp"
                    android:lines="1"
                    android:focusable="false"
                    android:singleLine="true"
                    android:gravity="center_vertical"
                    android:textColor="@color/gray"
                    android:imeOptions="actionDone"
                    />

2、在列表中显示跑马灯效果,要在代码中设置该TextView的selected为true
textView.setSelected(true);
3、以上都设置了呀,仍然没显示跑马灯效果。我遇到的一种很坑可能,TextView设置成fill_parent或是很长,但是由于text设置的字数不够长,就当成普通文本一样显示,无效果了。

这里写图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值