原文地址: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. linux(Centos7)服务器硬件改动,进入Emergency模式

    例如移走了某块硬盘后,直接开机就会进入该模式 这是因为/etc/fstab没有正确执行的原因 解决方法: 1)在该模式下输入root密码进入单用户模式(我没试过,不知道行不行,如果不行的话就用忘记ro ...

  2. MySQL Execution Plan--数据排序操作

    MySQL数据排序 MySQL中对数据进行排序有三种方式:1.常规排序(双路排序)2.优化排序(单路排序)3.优先队列排序 优先队列排序使用对排序算法,利用堆数据结构在所有数据中取出前N条记录. 常规 ...

  3. Using gcc stack debug skill

    The stack error is hard to debug, but we can debug it assisted by the tool provided by GCC. As we kn ...

  4. 01c++学习

    #include"iostream" using namespace std; void main01() { //printf("hello_world\n" ...

  5. Python __slots__的使用

    每个类在实例化时都会被分配一个dict,通过 实例.__dict__来访问,dict记录了实例的所有属性 如: class Man(object): pass man = Man()print(man ...

  6. [转]JBoss7中domain、standalone模式介绍

    JBoss AS7 可实现为云做好准备的架构,并可使启动时间缩短十倍,提供更快的部署速度并降低内在的占用.JBoss Enterprise Application Platform 6 的核心是JBo ...

  7. React 中的 Component、PureComponent、无状态组件 之间的比较

    React 中的 Component.PureComponent.无状态组件之间的比较 table th:first-of-type { width: 150px; } 组件类型 说明 React.c ...

  8. URL编码规则

    一.问题的由来 问题:当url地址中包含&.+.%等特殊字符(主要是传递参数时,参数的内容中包含这些字符)时,地址无效.比如http://10.190.0.0:108/doc/test+des ...

  9. 关于plot画图的原理

    首先是导入的: Import matplotlib.pyplot as plt 这份导入要背住,没事就是需要你进行导入的: 然后就是画图了,下面举一个例子: import numpy as np im ...

  10. Centos6.7 运行 eclipse出错解决办法

    今天在centos下运行eclipse c++出现来点问题.主要原因是jdk点安装以及环境变量始终不对. 尝试在/etc/profile中手动配置,也没有成功. 做了如下步骤成功解决. 1.查看jdk ...