TextView: android中TextView实现单行跑马灯
来源:互联网 发布:知乎 说学逗唱 编辑:程序博客网 时间:2024/05/22 05:57
textview中内容过长的话自动换行,但是调用measureText函数时发现返回值很不准确,单位也不确定,是pixel还是dip,都不准。后来想起textview中有个内容过长加省略号的属性,即ellipsize,可以较偷懒地解决这个问题,哈哈~
用法如下:
在xml中
android:ellipsize = "end" 省略号在结尾
android:ellipsize = "start" 省略号在开头
android:ellipsize = "middle" 省略号在中间
android:ellipsize = "marquee" 跑马灯
最好加一个约束android:singleline = "true"
当然也可以用代码语句
tv.setEllipsize(TextUtils.TruncateAt.valueOf("END"));
tv.setEllipsize(TextUtils.TruncateAt.valueOf("START"));
tv.setEllipsize(TextUtils.TruncateAt.valueOf("MIDDLE"));
tv.setEllipsize(TextUtils.TruncateAt.valueOf("MARQUEE"));
最好再加一个约束tv.setSingleLine(true);
不仅对于textview有此属性,对于editext也有,不过它不支持marquee
跑马灯效果没有做出来····
===查了一下
布局文件xml中完整配置如下
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/textview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:ellipsize="marquee"----跑马灯 android:singleLine="true"----单行显示 android:focusable="true"----该textView适中获取焦点,只有获取焦点才能实现跑马灯效果,当然喽如果是多个TextView列表需要把这个属性去掉才能实现点击那个view那个view跑 android:marqueeRepeatLimit="marquee_forever"----一直循环跑(可以换成相应数字此时对应-1),把这句去掉也可以实现循环跑纳闷,环境是模拟器4.0 android:focusableInTouchMode="true"----该句必须有 />
主文件是:
public class Main extends Activity{/** Called when the activity is first created. */private TextView textView1;@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);textView1 = (TextView) this.findViewById(R.id.textview);String html = "中新网10月10日电 据外电报道,美国科学家罗伯特J。<a href='http://www.baidu.com'>勒夫科维兹</a>(Robert J. Lefkowitz)与布莱恩·K·卡比尔卡(Brian K. Kobilka)因在G蛋白偶联受体方面的研究获得2012年诺贝尔化学奖。";CharSequence charSequence = Html.fromHtml(html);textView1.setText(charSequence);textView1.setMovementMethod(LinkMovementMethod.getInstance());}}
- android中TextView实现单行跑马灯
- android中TextView实现单行跑马灯
- TextView: android中TextView实现单行跑马灯
- android中TextView实现跑马灯效果
- Android中TextView实现跑马灯效果
- android--TextView实现跑马灯
- Android TextView实现跑马灯
- TextView实现跑马灯
- TextView实现跑马灯
- TextView实现跑马灯
- TextView实现跑马灯
- TextView实现跑马灯
- TextView单行滚动效果(跑马灯)
- android TextView跑马灯
- Android TextView跑马灯
- Android TextView跑马灯
- Android TextView 跑马灯
- 实现Android中TextView的跑马灯效果
- 终于解决了 在ActivityGroup中捕获Back事件(根据上篇日志的分析)
- Android上的Back键事件捕获
- 懒了好久,不是不愿意写,只是太忙了。可是发现,忙并不一定被认同。
- 《设计模式 ● 外观》之业务场景
- 文章14:Nginx变量总结(agentch的Nginx教程总结版)
- TextView: android中TextView实现单行跑马灯
- 星图
- QT中QWidget、QDialog及QMainWindow的区别
- c++ 覆盖
- 439 - Knight Moves
- [hnoi2008]玩具装箱题解(斜率优化的dp)
- light oj 1128
- 2012 ICPC成都网络赛题解
- 平面空间的分割问题总结