TextView跑马灯可以让显示不完的文字,以动画的形式滚动显示,但今天写了竟然没有任何效果这就很郁闷了!原来是没有获取到焦点

    <TextView  android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dp" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:marqueeRepeatLimit="marquee_forever" android:scrollHorizontally="true" android:singleLine="true" android:text="@string/android" android:textColor="#9351e4" android:textSize="24sp" />

这里必须要设置的几个属性

        android:ellipsize="marquee"//文字显示不完全,以什么方式显示(这里就以滚动的行形式)        android:focusable="true"//获得焦点        android:focusableInTouchMode="true"//获得触摸焦点        android:marqueeRepeatLimit="marquee_forever"//滚动模式        android:scrollHorizontally="true"//横向滚动        android:singleLine="true"//以单行文本显示
//几个不同的值android:ellipsize="start"//开头以...隐藏文字                   middle//中间以...隐藏文字                   end//结尾以...隐藏文字

显示的文字必须要超出给定的宽度,到这里如果不出意外就可以看到文字滚动了。

当你的界面view太多的时候,往往这个TextView就不一定能够获取到焦点,获取不到焦点也就看不懂跑马灯效果了下面给出解决办法

/** *自定义TextView 重写isFocused()函数,让他放回true也就是一直获取了 *焦点效果自然也就出来了,如果这都不能解决那肯定就不是焦点问题了。 *那就要找到问题,在想办法解决 */public class MarqueTextView extends TextView {    public MarqueTextView(Context context, AttributeSet attrs, int defStyle) {        super(context, attrs, defStyle);    }    public MarqueTextView(Context context, AttributeSet attrs) {        super(context, attrs);    }    public MarqueTextView(Context context) {        super(context);    }    @Override    public boolean isFocused() {        return true;    }}

更多相关文章

  1. android学习五(android中基本控件的使用)
  2. android学习---通过android帮助学习TextView属性
  3. android之layout_weight体验(实现按比例显示)
  4. Android(安卓)使用WebView加载含有echarts的页面,截图不显示的解
  5. Android图形显示系统(一)
  6. android EditText彻底搞定输入框隐藏/显示背景 可编辑输入问题
  7. Edittext禁止输入回车键以及单行显示解决方案
  8. android:ellipsize属性的含义
  9. [置顶] Android中View的加载过程

随机推荐

  1. Android解析中国天气接口JSon数据,应用于
  2. [置顶] Android系统移植与调试之------->
  3. Android(安卓)ndk 开发环境搭建 和 示例
  4. Android开发5――文件读写
  5. android中Parcelable接口的使用
  6. android制作开关机动画注意事项
  7. Android初级教程理论知识(第一章快速入门)
  8. Android(安卓)关于android:foreground设
  9. Android笔试总结
  10. Android(安卓)开机图片/文字/动画 修改