android标题栏跑马灯,Android跑马灯效果

一.第一种方法

1.在TextView中设置相关属性

1. android:ellipsize="marquee" 设置跑马灯显示效果

2. android:focusable="true" 获得焦点才能滚动

3. android:marqueeRepeatLimit="-1" 设置滚动次数 1代表1次 -1代表无限循环

4. android:singleLine="true" 必须单行显示

5. android:focusableInTouchMode="true" 获得焦点才能滚动```

2.问题:

1.这种方法实现的效果不是很理想,刚进入页面的时候Title滚动效果略微卡顿

2.在切换到全屏之后在切换回竖屏状态下时,TextView的滚动效果停止了

二.第二种方法

1.写一个自定义的TextView继承TextView,重写isFocused方法,返回True,用此方法来获得焦点

1.在xml控件中写上第一种方法的1.3.4就可以了

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);

}

@SuppressLint("NewApi")

public MarqueeTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {

super(context, attrs, defStyleAttr, defStyleRes);

}

@Override

public boolean isFocused() {

return true;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值