欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 科技 > 能源 > Android TextView 跑马灯

Android TextView 跑马灯

2025/3/15 23:33:50 来源:https://blog.csdn.net/CHNE_TAO_EMSM/article/details/146252777  浏览:    关键词:Android TextView 跑马灯

需求:

1:让文本自动滚动

解决:

<TextViewandroid:id="@+id/textView"android:layout_width="80dp"android:layout_height="wrap_content"android:background="@color/cl_888"android:fontFamily="@font/arial"android:ellipsize="marquee"android:focusable="true"android:focusableInTouchMode="true"android:marqueeRepeatLimit="marquee_forever"android:singleLine="true"android:text="这是一个很长的文本,用于测试跑马灯效果。"android:textColor="#FFF176"android:textSize="20px"android:textStyle="bold"tools:ignore="TextContrastCheck" />
try {TextView textView = mRootView.findViewById(R.id.textView);textView.setSelected(true);textView.setOnClickListener(v -> ToastHelps.showToast(getContext(), "" + textView.getText().toString()));} catch (Exception e) {e.printStackTrace();}

xml必须设置:

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

代码必须设置:

textView.setSelected(true);

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词