前言

由于项目需要实现跑马灯效果,测试了好几个办法才成功。所以特此记录一下。

方法

1.在布局文件加入:

        android:ellipsize="marquee"        android:focusable="true"        android:focusableInTouchMode="true"        android:marqueeRepeatLimit="marquee_forever"        android:scrollHorizontally="true"        android:singleLine="true"

2.重写TextView,使isFocused()返回true

public class MarqueeTextView extends TextView {    public MarqueeTextView(Context context) {        super(context);        // TODO Auto-generated constructor stub    }    public MarqueeTextView(Context context, AttributeSet attrs) {        super(context, attrs);        // TODO Auto-generated constructor stub    }    public MarqueeTextView(Context context, AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);        // TODO Auto-generated constructor stub    }    public MarqueeTextView(Context context, AttributeSet attrs,            int defStyleAttr, int defStyleRes) {        super(context, attrs, defStyleAttr, defStyleRes);        // TODO Auto-generated constructor stub    }    @Override    public boolean isFocused() {        return true;    }}

我发现有的布局只需要第一中方法,但是有的布局却需要同时两种方法集合一起才生效。可能是我的布局含有动画,比较复杂。

更多相关文章

  1. android 一行两个按钮居中 布局
  2. android中Drawable方法详解
  3. 【精品教程】Android高手进阶教程pdf分享
  4. 【精品教程】Android高手进阶教程pdf分享
  5. Android系统启动——5 zyogte进程(Java篇)
  6. 【精品教程】Android高手进阶教程pdf分享
  7. android scrollview组件禁止滑动的方法
  8. [Android]Android布局文件中的android:id="@*"属性使用方法汇总
  9. [Android]Android布局文件中的android:id="@*"属性使用方法汇总

随机推荐

  1. Android(安卓)发布GitHub项目到JitPack
  2. android中判断当前运行activity名的方法
  3. FastBoot BootLoader Recovery 模式解释
  4. Android(安卓)开发常用命令
  5. TimePicker使用全解
  6. Android SDK更新问题解决
  7. AndroidManifest.xml文件详解(manifest)
  8. 关于android USB Host 串口编程
  9. Android开发9――Activity的启动模式
  10. android 7.0 关机流程详细分析