它们的定义TextView使之具有跑马灯的效果

一、引入问题
使用通用textview快乐效应,焦点事件不启动滚动,button目前的焦点事件,但丑,因此,需要定制TextView 天生焦点

个textview
FocusedTextView.java

package com.xuliugen.mobilesafe.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.ViewDebug.ExportedProperty;
import android.widget.TextView;

/**
 * 跑马的效果。一開始没有焦点事件不会进行滚动
 * 
 * button有焦点事件。可是比較难看。因此须要自定一个TextView 一出生就有焦点
 * 
 * @author xuliugen
 * 
 */
public class FocusedTextView extends TextView {

    /**
     * 自己定义的view须要下面几个构造方法
     * 
     * @param context
     * @param attrs
     * @param defStyle
     */
    public FocusedTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public FocusedTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public FocusedTextView(Context context) {
        super(context);
    }

    /**
     * 当前并没有焦点。我仅仅是欺骗了Android系统
     */
    @Override
    @ExportedProperty(category = "focus")
    public boolean isFocused() {
        return true;
    }
}

那么我们引用的时候例如以下:

 <!-- 跑马灯的效果 :滚动的textView-->

    <com.xuliugen.mobilesafe.ui.FocusedTextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:singleLine="true"
        android:text="自己定义TextView使之具有跑马灯的效果自己定义TextView使之具有跑马灯的效果自己定义TextView使之具有跑马灯的效果"
        android:textSize="18sp" />

版权声明:本文博主原创文章。博客,未经同意不得转载。

posted @ 2015-09-23 14:25  zfyouxi  阅读(173)  评论(0编辑  收藏  举报