原文地址:http://blog.csdn.net/luoyebuguigen/article/details/37533631

关键是需要在TextView中嵌入requestForcus标签才会有效果。

<TextView   
        android:id="@+id/widget_item_name"  
        android:layout_height="wrap_content"  
        android:layout_width="wrap_content"  
        android:paddingLeft="10dip"  
        android:paddingRight="10dip"  
        android:text="Baby Room"  
        android:textColor="@android:color/white"  
        android:textSize="@dimen/testSize18"  
        android:singleLine="true"  
        android:ellipsize="marquee"  
        android:marqueeRepeatLimit="marquee_forever"  
        android:scrollHorizontally="true"  
        android:focusable="true"  
        android:focusableInTouchMode="true">  
        <requestFocus  
            android:focusable="true"  
            android:focusableInTouchMode="true"  
            android:duplicateParentState="true"/>  
    </TextView>

另外还有不使用ScrollView也可滚动的方法

TextView textview = (TextView) findViewById(R.id.text);  
            /**             *
             * 只有调用了该方法,TextView才能不依赖于ScrollView而实现滚动的效果。
             * 要在XML中设置TextView的textcolor,否则,当TextView被触摸时,会灰掉。
             */  
 
            textview.setMovementMethod(ScrollingMovementMethod.getInstance());

xml如下:

<TextView  
      android:layout_width="match_parent"  
      android:layout_height="wrap_content"  
      android:textSize="18sp"  
      android:scrollbars="vertical"  
       android:maxLines="12"  
      android:textColor="@color/white"  
      android:id="@+id/text"  
      android:text="hello world"  
     ></TextView>

备注:有些字符串为英文时,无法滚动,需要在字符串增加一个换行符

// 单曲   有些歌曲名和艺术家名是英文,无法进行滚动,需要再后面加一个回车符
ct_dec_playbar.setText(getString(R.string.play_title, title, artistname) + "\n");

Android app widget中实现跑马灯效果(非widget部件也实用)的更多相关文章

  1. android中实现跑马灯效果以及AutoCompleteTestView与MultiAutoCompleteTextView的学习

    跑马灯效果 1.用过属性的方式实现跑马灯效果 属性:                  android:singleLine="true" 这个属性是设置TextView文本中文字 ...

  2. Android 实现多行文本跑马灯效果

    Android TextView 实现跑马灯的效果很简单,只要加三个属性就可以了. android:ellipsize="marquee" android:focusable=&q ...

  3. Android TextView 横向滚动(跑马灯效果)

    Android TextView 中当文字比較多时希望它横向滚动显示,以下是一种亲測可行的方法. 效果图: 1.自己定义TextView,重写isFocused()方法返回true,让自己定义Text ...

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

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

  5. Android开发之TextView实现跑马灯效果

    TextView及其子类,当字符内容太长显示不下时可以省略号代替未显示的字符:省略号可以在显示区域的起始,中间,结束位置,或者以跑马灯的方式显示文字(textview的状态为被选中). 其实现只需在x ...

  6. Android textView点击滚动(跑马灯)效果

    布局文件: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:to ...

  7. 自定义有焦点的TextView实现广告信息左右一直滚动的跑马灯效果

    import android.content.Context; import android.text.TextUtils; import android.util.AttributeSet; imp ...

  8. TextView标签的属性和跑马灯效果

    text:显示的内容 textSize:文本的大小 textColor:文本的颜色 visibility:可见性  默认可见,invisible:表示不可见,但对控件的显示区域做了保留 gone:隐藏 ...

  9. Android 开发笔记___textvieww__跑马灯效果

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

随机推荐

  1. zabbix监控第一台主机系统

    注意zabbix客户端和zabbix服务端版本要一致,否则很容易出问题 实验环境,在第一台centos7(ip为192.168.245.128,以下简称主机1)上安装zabbix服务器端,在第二台ce ...

  2. 对象的继承(prototype)

    修改构造函数的原型对象,批量修改所有子对象的继承关系

  3. 用express快速写一个hello world

    首页要具备 node.js环境, npm环境 创建一个目录, 然后进入此目录作为工作目录 mkdir myapp cd myapp 通过npm init 创建一个package.json文件 npm ...

  4. malloc的使用、用malloc动态分配内存以适应用户的需求的源代码实例

    int len; ; printf("please enter the size that you want: "); scanf("%d", &len ...

  5. Linux系统如何模拟Http的get或post请求?

    一.get请求: 1.使用curl命令: curl “http://www.baidu.com” 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i “http://www ...

  6. eclipse中如何去掉复制代码有行号的数字

    当我想查找别人资料,想复制别人的代码,但别人的代码中序号行数数字,怎么能快速去除呢,如以下截图所示  首先将你的带有行号的代码拷到一个类中.你会看到一大堆的错误,不用急.   注意将视图切换到java ...

  7. svn already lock解决方法

    svn在pull的时候,出现svn already lock 错误.只需要在Cleanup里面勾选Break locks

  8. Azkaban介绍+安装部署+实战案例

    Azkaban介绍 什么是azkaban?1.工作流的作业调度系统2.通过k.v指令写法描述工作流节点3.可以通过web界面去管理工作流 Azkaban安装部署 2.3.1 准备工作 Azkaban ...

  9. Flume 拦截器(interceptor)详解

    flume 拦截器(interceptor)1.flume拦截器介绍拦截器是简单的插件式组件,设置在source和channel之间.source接收到的事件event,在写入channel之前,拦截 ...

  10. Vivado使用技巧(1)

    Vivado使用技巧 (1) 1. 2.复位准则: 3. 4. 5. 6. 7. 8.