Android成长日记-仿跑马灯的TextView
在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢?
---------------------------------------------------------------------
以下列出解决方法:
1. 新建TextView控件
<TextView
android:id="@+id/textView"
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/demo"/>
2. 重写TextView控件的样式(新建MarqueeText.java)
public class MarqueeText extends TextView {
public MarqueeText(Context context) {
super(context);
}
public MarqueeText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean isFocused() {
return true; //默认为false,设置为true为了让每个TextView都获取焦点
}
}
3. 将<TextView />更改为<com.demo.marqueetextview.MarqueeText.java[s1]
------à>>>这样的话就实现了对TextView的重写
===================================================
以上方法即实现了仿跑马灯效果的TextView
2015-01-31
[s1]这个地方为重写的java文件所在的包(精确到java文件~)
Android成长日记-仿跑马灯的TextView的更多相关文章
- Android 开发笔记___textvieww__跑马灯效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android使用Canvas实现跑马灯
网上的很多的教程都是通过更改TextView的属性进行跑马灯的设计.这样做有很多的缺点: 1.如果TextView没有获取焦点,那么跑马灯的效果无法实现. 2.如果文本长度小于TextView的宽度, ...
- Android成长日记-使用GridView显示多行数据
本节将实现以下效果 Ps:看起来很不错的样子吧,而且很像九宫格/se ----------------------------------------------------------------- ...
- Android成长日记-Fragment
(一)Android在3.0中引入了Fragment的概念,主要目的是用在大屏幕设备上—例如平板电脑上,支持更加动态和灵活的UI设计.平板电脑的屏幕要比手机大的多,有更多的空间放更多的UI组件,并且这 ...
- Android 用ViewFlipper实现跑马灯效果的公告提示
1.代码部分private void initViewFlipper(final HomepageListModel.Notice notice) { for (int i = 0; i < n ...
- Android成长日记-Android四大组件之Service组件的学习
1.什么是Service? Service是Android四大组件中与Activity最相似的组件,它们都代表可执行的程序,Service与Activity的区别在于:Service一直在后台运行,它 ...
- Android成长日记-数据存储之SQLite[1]
[SQLite简介] SQLite是R.Richard Hipp用C语言编写的开源嵌入式数据库引擎.它支持大多数的SQL92标准,并且可以在所有主要的操作系统上运行 ---支持高达2TB大小的数据库: ...
- Android成长日记-五大布局
1. 五布局之线性布局LinearLayout 特点:它包含的子控件将以横向或竖向的方式排列 ps:android:gravity=”center|bottom”(gravity允许多级联用) Tip ...
- Android成长日记-数据存储之SharedPreferences
数据篇-SharedPreferences Android的四种存储方式 1. SharedPreferences 2. SQLite 3. Content Provider 4. File ---- ...
随机推荐
- CastleActiveRecord在多线程 事务提交时数据库资源竞争导致更新失败的测试结果记录
CastleActiveRecord 经过测试,隔离级别: // 摘要: , , , , , , , ...
- Construct Binary Tree from Inorder and Postorder Traversal
Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of ...
- Theano2.1.14-基础知识之理解为了速度和正确性的内存别名
来自:http://deeplearning.net/software/theano/tutorial/aliasing.html Understanding Memory Aliasing for ...
- js的offsetWidth,offsetHeight,offsetLeft,offsetTop
js的offsetWidth,offsetHeight,offsetLeft,offsetTop
- android之视频播放
视频播放和音频播放一样,都是使用MediaPlayer来播放的,区别就是MediaPlayer播放视频时是直接在Activity中实现的,而音频播放则需要写到服务中去.使用MediaPlayer只支持 ...
- thinkphp 配置多数据库
1配置文件中配置另一数据库连接信息 例如: 'TestModelConfig' => array( //'配置项'=>'配置值' 'DB_TYPE' => 'mysql', // 数 ...
- C# has three timers
结论 *1.窗体timer和线程timer.计时器timer不同,因为后两者dispose之后,GC可以收集,而前者无法收集 *2.如果一个对象的成员函数正在被执行,那么这个对象肯定不会被收集 *3. ...
- 创建Maven项目
在MyEclipse10中创建Maven Web项目 1.构建maven项目 2.将maven项目转换成Dynamic Web Project 3.设置部署集 4.pom.xml文件配置 参考: ht ...
- Java--剑指offer(7)
31.求出1~13的整数中1出现的次数,并算出100~1300的整数中1出现的次数?为此他特别数了一下1~13中包含1的数字有1.10.11.12.13因此共出现6次,但是对于后面问题他就没辙了.AC ...
- 标准Web系统的架构分层
标准Web系统的架构分层 – 转载请注明出处 1.架构体系分层图 在上图中我们描述了Web系统架构中的组成部分.并且给出了每一层常用的技术组件/服务实现.需要注意以下几点: 系统架构是灵活的,根据需求 ...