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

来源:互联网 发布:java缩小图片尺寸 编辑:程序博客网 时间:2024/05/22 17:30

在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"        />
这样就可以同时实现两个跑马灯的效果了。

0 0
原创粉丝点击