android无焦点跑马灯滚动,Android跑马灯无焦点滚动

本文介绍了如何在Android中实现无焦点时跑马灯效果仍然持续滚动。通过自定义TextView(MarqueeText)并重写isFocused方法、onFocusChanged方法和onWindowFocusChanged方法,即使在Dialog弹出时也能保持跑马灯滚动。示例代码展示了具体的实现过程。

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

如果对显示没有特别要求可以直接使用属性就能做到,在布局文件中将TextView属性设置一下:

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:ellipsize="marquee"

android:focusable="true"

android:focusableInTouchMode="true"

android:marqueeRepeatLimit="marquee_forever"

android:scrollHorizontally="true"

android:singleLine="true"

android:text="哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈"

android:textSize="17sp" />

关键代码如下:

//设置为跑马灯显示

android:ellipsize="marquee"

//获取焦点

android:focusable="true"

//可以通过toucth来获得focus

android:focusableInTouchMode="true"

//设置重复的次数

android:marqueeRepeatLimit="marquee_forever"

//单行显示文字

and

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值