跑马灯效果(文字滚动)
来源:互联网 发布:软件测试 翻译 编辑:程序博客网 时间:2024/05/22 00:09
所谓跑马灯效果就是当文字超过控件所能容纳的空间时,在控件内滚动的效果。
要实现这样的效果需要在布局文件中加上:
android:singleLine=”true”android:ellipsize=”marquee”android:focusableInTouchMode=”true”android:focusable=”true”
需要注意的是:layout_width=”"要写成固定值,不能是wrap_content或者fill_parent,而且要比text长度长。
另外还可以设置滚动的次数android:marqueeRepeatLimit=”";
android:marqueeRepeatLimit=”marquee_forever”表示一直滚动。
但是这种跑马灯只有在控件获得焦点时在能滚动,要想让控件里的内容一直滚动就要定制该控件,重写里面的三个方法:
package com.market.ui.view;import android.content.Context;import android.graphics.Rect;import android.util.AttributeSet;import android.widget.TextView;public class ScrollForeverTextView extends TextView {public ScrollForeverTextView(Context context) {super(context);// TODO Auto-generated constructor stub}public ScrollForeverTextView(Context context, AttributeSet attrs) {super(context, attrs);}public ScrollForeverTextView(Context context, AttributeSet attrs,int defStyle) {super(context, attrs, defStyle);}@Overrideprotected void onFocusChanged(boolean focused, int direction,Rect previouslyFocusedRect) {if (focused)super.onFocusChanged(focused, direction, previouslyFocusedRect);}@Overridepublic boolean isFocused() {return true;}}
下面就是要在布局文件里使用这个控件了:
<com.market.ui.view.ScrollForeverTextView android:id="@+id/name" android:layout_width="140dip" android:layout_height="fill_parent" android:layout_weight="1" android:ellipsize="marquee" android:gravity="left|center_vertical" android:lines="1" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:textColor="#000000" android:textSize="16sp" />
- 【Android】跑马灯效果(文字滚动)
- 跑马灯效果(文字滚动)
- --------------------【Android】跑马灯效果(文字滚动)
- 跑马灯效果 文字上下滚动效果
- 浅谈android的跑马灯效果(文字滚动)
- 浅谈android的跑马灯效果(文字滚动)
- TextView文字横向滚动(跑马灯效果)
- 浅谈android的跑马灯效果(文字滚动)
- 浅谈android的跑马灯效果(文字滚动)
- 浅谈android的跑马灯效果(文字滚动)
- 浅谈android的跑马灯效果(文字滚动)
- 浅谈android的跑马灯效果(文字滚动)
- android的跑马灯效果(文字滚动)
- TextView实现跑马灯效果(文字滚动)
- java 通知跑马灯效果 (文字滚动)
- TextView 文字滚动 跑马灯效果
- 安卓文字过长,跑马灯文字滚动效果
- TextView跑马灯效果,也就是,自动滚动文字的效果。
- Windows Shell编程-第六章.快捷方式的最短路径
- 关于图片的那些事
- How to Print a PDF File Using Cocoa
- Oracle Form 信息提示框之基本用法
- hdu 敌兵布阵 线段树基础
- 跑马灯效果(文字滚动)
- 数据库学习实践(二)----记录浏览
- Windows Shell编程-第七章.侵入Shell
- Java程序员面试中的多线程问题
- getchar()函数 & EOF
- hdu I hate it 区间最大值 线段树
- V880+ 提示磁盘空间不足的解决方法:(dalvik-cache 映射)
- 为什么说敏捷开发不是方法论?
- hdu Just a Hook 线段树成段更新.cpp