TextView实现文字滚动需要以下几个要点:

  1.文字长度长于可显示范围:android:singleLine="true"
  2.设置可滚到,或显示样式:android:ellipsize="marquee"
  3.自定义滚动的ScrollingTextView
 public class ScrollingTextView extends TextView {

     public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
} public ScrollingTextView(Context context, AttributeSet attrs) {
super(context, attrs);
} public ScrollingTextView(Context context) {
super(context);
} @Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if (focused)
super.onFocusChanged(focused, direction, previouslyFocusedRect);
} @Override
public void onWindowFocusChanged(boolean focused) {
if (focused)
super.onWindowFocusChanged(focused);
} @Override
public boolean isFocused() {
return true;
} }

在布局里调用自定义的TextView:

 <com.example.rolltextdemo.ScrollingTextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:text="@string/hello_world" />

Android TextView文字横向自动滚动(跑马灯)的更多相关文章

  1. Android:TextView 自动滚动(跑马灯) (转)

    Android:TextView 自动滚动(跑马灯)       TextView实现文字滚动需要以下几个要点: 1.文字长度长于可显示范围:android:singleLine="true ...

  2. Android TextView 字数过多,用跑马灯滚动形式实现

    上代码: <TextView android:layout_width="120dp" android:layout_height="wrap_content&qu ...

  3. js无缝滚动跑马灯

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Android:TextView文字跑马灯的效果实现

    解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...

  5. Android 如何实现带滚动条的TextView,在更新文字时自动滚动到最后一行?

    1.在布局文件中放置一个TextView,给它添加scrollbars和fadeScrollbars两个属性. 如下设置:滚动条为垂直滚动条,并且一直可见(当TextView中的文字行数超过页面能显示 ...

  6. TextView文字横向自己主动滚动

              效果截图:                              watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjI4Nj ...

  7. Android中TextView不获取焦点可以实现跑马灯的效果

    之前在网上找了很多关于TextView的跑马灯效果实现的例子,实现起来都存在一些问题,例如一种是完全重画一个跑马灯,还有就是只设置TextView的相关属性使其具有跑马灯的效果,总的来说这两种方法都是 ...

  8. Unity3D 文字滚动跑马灯效果

    需求 在日常游戏中,文字滚动效果是比较常用的.例如日常游戏顶部的新闻公告,聊天系统的文字滚动,都属于这个范围. 思路 由于使用的地方比较广泛,所以希望能够尽量独立的游戏之外,能够做到随处使用的功能.N ...

  9. Textview在Listview中实现跑马灯效果

    textview添加属性:   android:singleLine="true" 表示单行显示   android:ellipsize="marquee" 设 ...

随机推荐

  1. 转!!各种数据库的jdbc驱动下载及连接方式

    各种数据库驱动 数据库名称 下载地址 说明 Mysql http://www.mysql.com/products/connector/j/ Shipped. But need to download ...

  2. js树目录结构

    jstree https://www.jstree.com/demo/ treejs http://www.treejs.cn/v3/demo.php#_206

  3. Difference between Hard Clip(H) and Soft Clip(S) in Samtools CIGAR string

    一般人都知道 H 和 S 的表面上的区别,即 S 就是 soft, H 就是 hard,S 后,序列里还是会保留序列的信息,而 H 则不会. ----------------------------- ...

  4. ubuntu server nginx 安装与配置

    ubuntu server nginx 安装与配置 一:关于nginx http://wiki.ubuntu.org.cn/Nginx http://nginx.org/cn http://wiki. ...

  5. [转载]SoapUI 参数化&数据库连接

    引用自 : http://www.cnblogs.com/liulinghua90/p/4954045.html 如果是没有代码能力的小白,要利用工具进行接口测试的时候,经常会遇到接口地址 或者接口参 ...

  6. WPF:行列显示

    新建显示病人信息控件PatientElement Add-->NewItem-->WPF-->UserControl(WPF),名称:PatientElement.xmal < ...

  7. iOS开发几年了,你清楚OC中的这些东西么!!!?

    iOS开发几年了,你清楚OC中的这些东西么!!!? 前言 几年前笔者是使用Objective-C进行iOS开发, 不过在两年前Apple发布swift的时候,就开始了swift的学习, 在swift1 ...

  8. maven搭建java ee项目

    1.点击File->New->Other,选择maven project   2.选择maven project,点击Next,,而后再点击next,进入如下界面 如图选择最后一个,点击n ...

  9. 在Handler.ashx文件中使用session

    使用jquery调用handler文件中的方法,需要使用session,默认生成的文件中,不可以直接使用session.按照以下步骤,即可以通过session与其他的aspx页面的session进行数 ...

  10. 转--CSS选择器详解(一)常用选择器

    今天复习一下CSS的知识,看了篇文章觉得很好,转来备用. 转自:http://www.cnblogs.com/fattydoit/p/3492028.html 目录 类型选择器 类选择器 ID选择器 ...