Android:TextView 自动滚动(跑马灯) (转)
Android:TextView 自动滚动(跑马灯)
public class AlwaysMarqueeTextView extends TextView { public AlwaysMarqueeTextView(Context context) {
super(context);
} public AlwaysMarqueeTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} public AlwaysMarqueeTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} @Override
public boolean isFocused() {
return true;
}
在布局XML文件中加入这么一个AlwaysMarqueeTextView,这个加入方法也是刚刚学的。
<com.examples.AlwaysMarqueeTextView
android:id=“@+id/AMTV1″
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:lines=“1″
android:focusable=“true”
android:focusableInTouchMode=“true”
android:scrollHorizontally=“true”
android:marqueeRepeatLimit=“marquee_forever”
android:ellipsize=“marquee”
android:background=“@android:color/transparent”
/>
ellipsize属性
设置当文字过长时,该控件该如何显示。有如下值设置:”start”—–省略号显示在开头;”end”——省略号显示在结尾;”middle”—-省略号显示在中间;”marquee” ——以跑马灯的方式显示(动画横向移动)
EidtText和textview中内容过长的话自动换行,使用android:ellipsize与android:singleine可以解决,使只有一行。
EditText不支持marquee
用法如下:
在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);
marqueeRepeatLimit属性
在ellipsize指定marquee的情况下,设置重复滚动的次数,当设置为marquee_forever时表示无限次。
focusable属性
自己猜测的,应该是能否获得焦点,同样focusableInTouchMode应该是滑动时能否获得焦点。
组合View的问题:
< LinearLayout
xmlns:android =“http://schemas.android.com/apk/res/android”
android:orientation =“vertical”
android:gravity =“center_vertical”
android:background =“@drawable/f_background”
android:layout_width =“fill_parent”
android:focusable =“true”
android:layout_height =“50px” >
< TextView
android:id =“@+id/info_text”
android:focusable =“true”
android:layout_width =“fill_parent”
android:layout_height =“wrap_content”
android:text =“test marquee .. “
android:textColor =“@color/black”
android:singleLine =“true”
android:ellipsize =“marquee”
android:marqueeRepeatLimit =“3″
android:textSize =“18sp”
/>
< TextView
android:id =“@+id/date_text”
android:layout_width =“fill_parent”
android:layout_height =“wrap_content”
android:layout_gravity =“bottom”
android:textColor =“@color/gray”
android:text =“2010/05/28″
android:textSize =“12sp”
/>
</ LinearLayout >
上面示例中2个TextView组合为一个View,由于设置了LinearLayout为focusable而TextView就没法取得焦点了,这样 这个TextView的跑马灯效果就显示不出来,就算你也设置TextView的 android:focusable=
"true"
也是 没用的. 这个时候就要使用addStatesFromChildren 这个属性了,在LinearLayout中设置这个属性,然后设置TextView的focusable=
"true"
就可以了.关于 addStatesFromChildren的说明:
Sets whether
this
ViewGroup's drawable states
also include its children's drawable states.
来自:http://hmifly.blog.163.com/blog/static/1285835072011322352406/
Android:TextView 自动滚动(跑马灯) (转)的更多相关文章
- Android TextView文字横向自动滚动(跑马灯)
TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true" 2.设置可滚到,或显示样式:android: ...
- Android TextView 横向滚动(跑马灯效果)
Android TextView 中当文字比較多时希望它横向滚动显示,以下是一种亲測可行的方法. 效果图: 1.自己定义TextView,重写isFocused()方法返回true,让自己定义Text ...
- js无缝滚动跑马灯
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Android 文字自动滚动(跑马灯)效果的两种实现方法[特别好使]
有时候在xml中写的跑马灯效果不滚动:原因有以下 Android系统中TextView实现跑马灯效果,必须具备以下几个条件: 1.android:ellipsize=”marquee” 2.TextV ...
- Android成长日记-仿跑马灯的TextView
在程序设计中有时候一行需要显示多个文字,这时候在Android中默认为分为两行显示,但是对于必须用一行显示的文字需要如何使用呢? ----------------------------------- ...
- android TextView实现滚动显示效果
在android中,如果设置了TextView控件为单行显示,且显示的文本太长的话,默认情况下会造成显示不全的情况,这种情况下我们需要设置该控件属性如下: <TextView android:i ...
- android TextView 垂直滚动 用动画实现
项目中需要让TextView 滚动一会显示一行一会显示一行 想了下用移动动画实现.但是实际中在整这个动画时调了好久.主要用到的动画方式是移动动画:TranslateAnimation 代码: PS: ...
- Android 开发笔记___textvieww__跑马灯效果
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...
- Android使用Canvas实现跑马灯
网上的很多的教程都是通过更改TextView的属性进行跑马灯的设计.这样做有很多的缺点: 1.如果TextView没有获取焦点,那么跑马灯的效果无法实现. 2.如果文本长度小于TextView的宽度, ...
随机推荐
- MySql 数据操作类
/// <summary> /// MySqlHelper 的摘要说明. /// </summary> public class MySqlHelper { public st ...
- IIS7.5配置SSL
1,首先需要准备两个证书(CA证书,服务器证书). CA证书由公共的CA机构提供,widnow系统内部已经内置了很多这类证书,如图(日文系统). 服务器证书是导入到IIS里面用的. 2,有了上面的认识 ...
- SQL Server 2008 Windows身份验证改为混合模式身份验证
1.在当前服务器右键进入“属性页”->“安全性”->勾选Sql Server和Windows身份验证模式->确定. 由于默认不启用sa,所以如果启用sa账户登录,则还需要如下设置: ...
- scanf中的[]
今天被问到一个问题,如何用scanf将 hello-my-world中的三个单词, hello my world 分别放到三个char数组中去 于是用到了scanf中的[] [ ] 扫描字符集合,比如 ...
- MyBatis知多少(24)存储过程
使用MyBatis配置来调用存储过程.为了理解这一章,首先需要了解我们是如何在MySQL中创建一个存储过程. 在继续对本节学习之前,可以自行学习MySQL存储过程. 我们已经在MySQL下有EMPLO ...
- 七牛portal可用性测试记
引言:2013年年底应七牛公司朋友的邀请,给他们的Portal进行可用性测试.七牛(http://www.qiniu.com/)一直专注于云存储基础服务,在业内颇有声誉.七牛云存储的后台选用并不常用的 ...
- Core Animation 学习
core animation 是在UIKit层之下的一个图形库,用于在iOS 和 OS X 实现动画. Core Animation管理App内容 core animation不是一个完整的绘图系统, ...
- 批量修改Project视图中Prefab的名字
简要代码如下: using UnityEditor; using UnityEngine; using System.IO; using System.Collections; using Syste ...
- C#连接Oracle简单教程
要点:本文主要介绍如何使用最简单的方法让C#操作Oracle数据库,不需要安装Oracle客户端之类的东西. 最近由于工作需要,要使用C#从SQLServer向Oracle导入数据.之前没有怎么接触过 ...
- Understanding CMS GC Logs--转载
原文地址:https://blogs.oracle.com/poonam/entry/understanding_cms_gc_logs Understanding CMS GC Logs By Po ...