Android自定义TextView实现跑马灯功能
发布时间:2020-05-28 21:09:52 所属栏目:Java 来源:互联网
导读:Android自定义TextView实现跑马灯功能
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 未用自定义TextView实现跑马灯代码: <Button
android:focusableInTouchMode="true"
android:singleLine="true"
android:ellipsize="marquee"
android:text="未使用自定义TextView的跑马灯效果"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
下面使用自定义TextView实现跑马灯: package com.zebra.mobilesafe.ui;
import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewDebug.ExportedProperty;
import android.widget.TextView;
/**
* 自定义一个TextView,是他天生就有焦点
* @author Administrator
*
*/
public class FocusTextView extends TextView {
public FocusTextView(Context context,AttributeSet attrs,int defStyle) {
super(context,attrs,defStyle);
// TODO Auto-generated constructor stub
}
public FocusTextView(Context context,AttributeSet attrs) {
super(context,attrs);
// TODO Auto-generated constructor stub
}
public FocusTextView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
/**
* 欺骗Android系统,让当前没有焦点的判断为true,实现button效果
*/
@Override
@ExportedProperty(category = "focus")
public boolean isFocused() {
// TODO Auto-generated method stub
return true;
}
}
然后在android的xml文件中,引用自定义实现,路径要是类的绝对路径 <com.zebra.mobilesafe.ui.FocusTextView
android:singleLine="true"
android:ellipsize="marquee"
android:text="使用自定义TextView的跑马灯效果"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
这样就可以在TextView中实现跑马灯效果了。 以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
