textView 跑马灯效果使用示例

package com.bbk.android.controls;

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

public class MarqueeTextView extends TextView{

    public MarqueeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    
    @Override
    protected void onFocusChanged(boolean focused, int direction,
            Rect previouslyFocusedRect) {
        // TODO Auto-generated method stub
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
        
         if(focused) super.onFocusChanged(focused, direction, previouslyFocusedRect);  

    }
    
    @Override
    public void onWindowFocusChanged(boolean hasWindowFocus) {
        // TODO Auto-generated method stub
        if(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus);
    }
    
    @Override
    @ExportedProperty(category = "focus")
    public boolean isFocused() {
        return true;
    }
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center" >

    <com.bbk.android.controls.MarqueeTextView
        android:id="@+id/listitemText"
        android:layout_width="90dp"
        android:layout_height="wrap_content"
        android:ellipsize="marquee"
        android:marqueeRepeatLimit="marquee_forever"
        android:scrollHorizontally="true"
        android:singleLine="true"
        android:textSize="16sp" >
    </com.bbk.android.controls.MarqueeTextView>

</LinearLayout>

 

posted @ 2012-11-27 11:50  jex  阅读(182)  评论(0)    收藏  举报