Android实现TextView跑马灯效果
2023-02-18 16:28:12 时间
前言
由于项目需要实现跑马灯效果,测试了好几个办法才成功。所以特此记录一下。
方法
1.在布局文件加入:
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
2.重写TextView,使isFocused()返回true
public class MarqueeTextView extends TextView {
public MarqueeTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
// TODO Auto-generated constructor stub
}
public MarqueeTextView(Context context, AttributeSet attrs,
int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
return true;
}
}
我发现有的布局只需要第一中方法,但是有的布局却需要同时两种方法集合一起才生效。可能是我的布局含有动画,比较复杂。
相关文章
- java和vue学生定位打卡小程序人脸识别打卡系统源码网站学生考勤系统
- Java疫苗预约小程序线上疫苗预约系统
- 移动研发提效?小程序容器技术来帮忙!
- 微信小程序(一)自定义导航栏和fixed失效及各机型兼容问题
- 微信小程序(二)学妹问我微信小程序左滑删除怎么实现
- 微信小程序(三)实现类似Vue中的 computed,watch 功能
- 微信小程序(四)绝对不可错过切换自定义菜单栏的骚操作
- 一文说透小程序插件及其作用价值
- android learning
- 微信小程序HTTPS - cenos apache 下安装SSL证书
- 3小时!开发ChatGPT微信小程序
- iOS 裁包大作战 —— JOOX Music 如何瘦身40MB
- 只需4步!带你成功将小程序转为APP
- 设计师应该了解的iOS应用开发基础知识
- 小程序容器技术成为组装式应用基础
- 「Native+小程序」,App热更新技术最优解
- 混合式App开发背景下,「Native+小程序」成为最优解
- 不改一行代码,就可以将微信小程序转成商业App?
- 技术分享|如何运用FinClip轻松将微信小程序转成商业App
- R8在Android手Q中的应用