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. Linux配置全局环境变量的方法

    总结3种方法: 1.修改/etc/profile    1.1 :首先在此文件中设置环境变量;    1.2:export  设置好的环境变量.  #view /etc/profile export ...

  2. Redhat 6.4_联网 yum 配置

    步骤简述----------------------------------------------------------------- 1. 准备软件包 下载第三步的软件包即可.由于是联网yum配 ...

  3. hiho1091_clicker背包问题

    问题 类似有限背包问题,题目链接:clicker 实现 #include<stdio.h> #include<cmath> #include<iostream> # ...

  4. phalcon: plugin 结合Manager事件管理、dispatcher调度控制器 监听sql日志记录或其他拦截出来

    可能用到的类 phalcon\mvc\use\plugin Phalcon\Mvc\Dispatcher as MvcDispatcher Phalcon\Events\Manager as Even ...

  5. flasCC技术点记录

    [待测试特性] 一.C接口导出相关 1.重载函数. 2.虚函数. 3.template相关 二.内存相关 1.as直接往c分配的内存写数据. 2.c直接往as对象写数据. 三.C访问AS 1.访问as ...

  6. java 对象 Serializable注意事项

    在序列化时,有几点要注意的: 1:当一个对象被序列化时,只保存对象的非静态成员变量,不能保存任何的成员方法和静态的成员变量. 2:如果一个对象的成员变量是一个对象,那么这个对象的数据成员也会被保存. ...

  7. Win7下Maven的安装与配置

    简介  官网:https://maven.apache.org/ Apache Maven,是一个(特别是Java软件)项目管理及自动构建工具,由Apache软件基金会所提供.基于项目对象模型(Pro ...

  8. C#引用Office.word出错的解决办法-无法嵌入互操作类型“Microsoft.Office.Interop.Word.ApplicationClass” 【转】

    本文章转自 suchso 1.系统找不到 Microsoft.Office.Interop.Word" "Could not load file or assembly 'Micr ...

  9. WPF: DatePicker

    获取DatePicker:date_Start上显示的时间date_Start.SelectedDate 比较两个dateTime类型的时间: DateTime StartDate =Convert. ...

  10. Combinations [LeetCode]

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...