一、想要效果

想让Android的TextView实现跑马灯效果,垂直或者横向文字滚动。

二、出现问题

设置了跑马灯相关属性后发现没有达到滚动的效果,在xml中设置属性如下

          

跑马灯效果属性介绍: 

       android:ellipsize="marquee"//文字显示不完全,以什么方式显示(marquee代码滚动)

  1. android:focusable="true"//获得焦点

  2. android:focusableInTouchMode="true"//获得触摸焦点

  3. android:marqueeRepeatLimit="marquee_forever"//滚动模式

  4. android:scrollHorizontally="true"//横向滚动

  5. android:singleLine="true"//以单行文本显示

  6. //几个不同的值

  7. android:ellipsize="start"//开头以...隐藏多余文字

  8. middle//中间以...隐藏多余文字

  9. end//结尾以...隐藏多余文字

注意:显示的文字必须要超出给定的宽度
 

三、原因分析

由于界面view太多,导致这个TextView就不一定能够获取到焦点,获取不到焦点也就没有跑马灯效果了

四、解决方案

  1. /** * Created by francisbingo on 2019-09-26 10:44 * * view层级太多,为了实现跑马灯效果的自定义view */public class MarqueeTextView extends TextView {    public MarqueeTextView(Context context) {        super(context);    }    public MarqueeTextView(Context context, @Nullable AttributeSet attrs) {        super(context, attrs);    }    public MarqueeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {        super(context, attrs, defStyleAttr);    }    @Override    public boolean isFocused() {        return true;    }}

     

更多相关文章

  1. android高仿抖音、点餐界面、天气项目、自定义view指示、爬取美
  2. android酷炫翻页效果+图形分析
  3. android的Material Design点击涟漪效果
  4. view属性大全
  5. Android(安卓)左右滑屏效果
  6. android listview 的一些属性
  7. Android之在Bitmap上涂鸦效果
  8. 好的网子
  9. android之字体阴影效果

随机推荐

  1. [Android] Code Style Guidelines for Co
  2. Android实现DES和3DES算法
  3. Android WebView访问SSL证书网页(onReceiv
  4. Android 动画ObjectAnimator中height和tr
  5. Android(安卓)应用程序 生命周期
  6. ImageButton动态改变按钮图片
  7. Android优质学习方法
  8. Android 6.0 - 申请动态权限
  9. Android源代码编译
  10. 【转】Android(安卓)SDK Setup使用及注意