自学360之滚动的TextView

本文介绍了一种在Android中使TextView的文字实现滚动显示的方法。通过创建自定义TextView类并覆盖isFocused方法,再结合XML配置中的特定属性,可以实现文字的循环滚动效果。

滚动的View既字体的滚动循环.

1.android:focusableInTouchMode="true"          //设置是否为滚动

   android:ellipsize="marquee"                             //设置为循环的滚动

但是对于TextView 它默认为False 所以是不可滚动的

所以 写个自定义的类来继承TextView

实现其中的几个方法

写IsFocued 方法 将返回值设置为True

@Override

@ExportedProperty(category = "focus")
public boolean isFocused() {
// TODO Auto-generated method stub
return true;      //欺骗系统
}

2.在实现的XML文件中调用就可以了

 <TextView.MyTextView
        android:focusableInTouchMode="true"
        android:ellipsize="marquee"
        android:id="@+id/tv"
        android:textSize="10dp"
        android:text="我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士我是360卫士11111111111111"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:singleLine="true"/>

3.即可实现文字的滚动功能了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值