android 怎么实现跑马灯效果

版权所有,禁止匿名转载;禁止商业使用。

自定义控件 FocusedTextView, 使android系统误以为它拥有焦点


public class FocusedTextView extends TextView {
     public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
         // TODO Auto-generated constructor stub
     }
     public FocusedTextView(Context context, AttributeSet attrs) {
         super(context, attrs);
         // TODO Auto-generated constructor stub
     }
     public FocusedTextView(Context context) {
         super(context);
         // TODO Auto-generated constructor stub
     }
     @ExportedProperty(category = "focus")
     public boolean isFocused() {  //永远拥有焦点
         // TODO Auto-generated method stub
         return true;
     }
 }

xml布局中使用此控件


<com.test.ui.FocusedTextView
 android:id="@+id/tv_marquee"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:singleLine="true"
 android:ellipsize="marquee"
 android:text="跑马灯效果!跑马灯效果!跑马灯效果!跑马灯效果!跑马灯效果!跑马灯效果!跑马灯效果!跑马灯效果!"
 android:textSize="30dp" />


0 0