您的位置:首页 > 编程语言

用代码简单的实现跑马灯效果

2016-01-06 20:26 495 查看
在res资源文件夹下的layout中定义一个TextView控件代码如下:

<TextView
android:text="@string/hehe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
/>


其中string中是你实现效果的文字。这样就可以实现你的跑马灯效果了。

如果想要同时实现两个跑马灯效果,需要你重新定义一个类来继承TextView然后重写它的三个方法,最后需要在重载他的一个isFocused方法,让它return
true;

.最后一步就是,用我们自定义的这个类(com.imooc.包名.类名)来替代textview.如下:

<com.example.android_06_demo.MyclassTextView
android:text="@string/hehe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
/>
<com.example.android_06_demo.MyclassTextView
android:text="@string/hehe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
/>
这样就可以同时实现两个跑马灯的效果了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: