Android TextView实现跑马灯
TextView实现跑马灯的效果:
例子一:
这个例子可以解决给一个TextView实现跑马灯的效果,但是不能解决给所有的TextView实现跑马灯的效果。
<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="这个项目的作用就是让这个单行的很长很长的单独一行的TextView实现跑马灯的效果。。。。。。" />
但是这种方法在有两个TextView的时候不能给两个TextView同时实现跑马灯的效果。
原因是:TextView默认的isFocused()方法默认只能给一个对象实现focused。
解决的办法是新建一个类MarqueeTextView继承TextView,让他的isFocused()方法返回true。(注意:子类MarqueeTextView需要实现父类的所有3个构造函数,不然会有问题)。
package com.example.textviewhorseracelamp; import android.content.Context;
import android.util.AttributeSet;
import android.widget.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() {
return true;
}
}
MarqueeTextView.java
<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"
> <com.example.textviewhorseracelamp.MarqueeTextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="这个项目的作用就是让这个单行的很长很长的单独一行的TextView实现跑马灯的效果。。。。。。" /> <com.example.textviewhorseracelamp.MarqueeTextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:text="这个项目的作用就是让这个单行的很长很长的单独一行的TextView实现跑马灯的效果。。。。。。" /> </RelativeLayout>
activity_main.xml
效果:

补充:像素
px不能根据分辨率进行缩放
dp,sp,dip可以根据分辨率进行缩放显示(现在以dp作为标准)
sp更多的用在文字的缩放
Android TextView实现跑马灯的更多相关文章
- Android:TextView文字跑马灯的效果实现
解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...
- Android开发之TextView实现跑马灯效果
TextView及其子类,当字符内容太长显示不下时可以省略号代替未显示的字符:省略号可以在显示区域的起始,中间,结束位置,或者以跑马灯的方式显示文字(textview的状态为被选中). 其实现只需在x ...
- Android 高级UI设计笔记05:使用TextView实现跑马灯的效果
1. 使用TextView属性实现跑马灯的效果: (1). 新建一个Android工程,命名为"MarqueeTextViewDemo",如下: (2). 来到activity_m ...
- android使用TextView实现跑马灯的效果(1)
android使用TextView实现跑马灯的效果 1.activity_main.xml <?xml version="1.0" encoding="utf-8& ...
- Android界面(1) 使用TextView实现跑马灯效果
方法一:(只能实现单个TextView的跑马灯效果)在TextView添加以下控件 android:singleLine="true"只能单行,超出的文字显示为"...& ...
- Android使用TextView实现跑马灯效果(自定义控件)
对于一个长的TetxView 折行显示是一个很好的办法,另一种方法就是跑马灯显示(单行滚动) 1.折行显示的长TextView <LinearLayout xmlns:android=" ...
- TextView: android:ellipsize="marquee" 跑马灯效果无效的问题
今天练习的时候想实现一个文字的跑马灯效果,本来想自己手动实现的,不过突然想起来android里的TextView属性似乎自带了这个效果,叫: android:ellipsize ,平时都是把它的属性值 ...
- android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习
跑马灯效果 1.用过属性的方式实现跑马灯效果 属性: android:singleLine="true" 这个属性是设置TextView文本中文字 ...
- android:ellipsize实现跑马灯效果总结(转)
最近无意间看到了涉及到跑马灯效果的代码,于是在网上查阅了很多资料,在这里对自己看的一些文章进行一下总结,顺便加上自己的一些体会. 让我们一步步逐渐向下. 首先我们要实现走马灯这样一个效果,通常来说 ...
随机推荐
- 简易web项目jdbcUtil
jdbc.username=root jdbc.password=root jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://mini1: ...
- 你用过Spring中哪些功能?
核心容器: IOC:依赖注入 AOP:日志记录,性能统计,安全控制,事务处理,异常处理 Spring MVC: Spring profile:生产和日常配置的切换 Spring事件触发功能:比较简单, ...
- uboot中CMD的实现
CMD配置位于config_cmd_default.h configs/at91/sam9g10ek.h 头文件位于include/command.h 41 struct cmd_tbl_s { ...
- 测试markdown编辑器
标题1 标题2 +++ 第一件事 +++ 第二件事 +++ 第三件事 |head|头|头栏| |body|body|body|
- php 抽象 继承 多态
1.继承和重载 !!!php中使用extends单一继承的方法 被继承的类 父类(基类) 继承者 子类(派生类) 如果说我们需要将父类方法重载(方法覆盖),在派生类里使用与基类方法重名的方法名称 ...
- 软件测试工具MonkeyTalk使用方法
1.简单介绍 MonkeyTalk软件测试工具由两部分构成:MonkeyTalk IDE 和 MonkeyTalk Agents MonkeyTalk IDE是Eclipse平台的工具,工能是:对iO ...
- 最大割(Maximum cut)
问题描述:把图中点分为两部分V1和V2,使得V1和V2之间的连边值最大.
- 第二百八十六节,MySQL数据库-MySQL事务操作(回滚)
MySQL数据库-MySQL事务操作(回滚) 事务用于将某些操作的多个SQL作为原子性操作,一旦有某一个出现错误,即可回滚到原来的状态,从而保证数据库数据完整性. 举例:有这样一张表 从表里可以看出张 ...
- Zookeeper CLI
ZooKeeper命令行界面(CLI)用于与ZooKeeper集合进行交互以进行开发.它有助于调试和解决不同的选项. 要执行ZooKeeper CLI操作,首先打开ZooKeeper服务器(“bin/ ...
- caffe源代码分析--Blob类代码研究
作者:linger 转自须注明转自:http://blog.csdn.net/lingerlanlan/article/details/24379689 数据成员 shared_ptr<Sync ...