当前位置:网站首页>MarqueeTextview(跑马灯)
MarqueeTextview(跑马灯)
2022-07-27 17:02:00 【Ashurol】
由于有时候TextView内容过长,实现跑马灯的状态,若一个Activity内只需一个TextView,可以为其添加以下属性
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
需要两个或多个,就要重新定义TextView类
public class MarqueeTextview extends TextView{
public MarqueeTextview(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public MarqueeTextview(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public MarqueeTextview(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
@Override
public boolean isFocused() {
// TODO Auto-generated method stub
return true;
}
}
布局文件TextView标签用包名类目代替
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.xin.marqueetextview.MainActivity" >
<com.example.xin.marqueetextview.MarqueeTextview
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
<com.example.xin.marqueetextview.MarqueeTextview
android:layout_below="@+id/tv_1"
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="@string/hello_world" />
</RelativeLayout>

边栏推荐
- 全球手机芯片设计领域首家!紫光展锐荣膺TMMi4级国际认证
- [basic knowledge of deep learning - 50] PCA dimensionality reduction principal component analysis
- 电商商城小程序项目完整源码(微信小程序)
- c语言:5、多维数组
- 【日常积累 - 07】cuda多版本切换
- Count the six weapons of the domestic interface cooperation platform!
- TSMC 5nm is about to mass produce: Apple A14 monopolizes 70% of the production capacity, and Huawei Kirin 1020 takes 30%
- Binary search tree
- IIS 发生未知FastCGI错误:0x80070005
- 二叉搜索树
猜你喜欢

带来高价值用户体验的低代码开发平台

汉字查拼音微信小程序项目源码

一种比读写锁更快的锁,还不赶紧认识一下

Flink 算子简介

golang设置国内镜像,vscode配置golang开发环境,vscode调试golang代码

c语言:c语言代码风格

应用程序池已被禁用

Programming jump

Complete source code of E-commerce mall applet project (wechat applet)

Debian recaptured the "debian.community" domain name, but it's still not good to stop and rest
随机推荐
Hardware acceleration of zero knowledge proof
Ericsson admitted bribery in China and other five countries and paid a fine of $1.06 billion to the United States
To create a MySQL data source resource group, you must choose to create a new exclusive data integration resource group? Or use a common resource group? thank you
技术实践干货 | 初探大规模 GBDT 训练
【深度学习基础知识 - 49】Kmeans
爱立信承认在中国等五国行贿,向美支付10.6亿美元罚款
C language: 7. How to use C language multi source files
来一遍《剑指Offer》03. 数组中重复的数字
C language: 12. GDB tool debugging C program
Anaconda下安装Talib库
Can set be used to define local variables in OPDS SQL
发布自己的npm组件库
Embedded C language structure
MFC高级控件之Tab控件( CTabCtrl )
IIS 发生未知FastCGI错误:0x80070005
Debian recaptured the "debian.community" domain name, but it's still not good to stop and rest
【深度学习基础知识 - 47】贝叶斯网络与朴素贝叶斯
下放三星3J1传感器:代码暗示Pixel 7人脸识别安全性将大增
C language: 9. Return in main function
Introduction to Flink operator