zoukankan      html  css  js  c++  java
  • 一个页面多个TextView跑马灯,与焦点无关

    package com.travelsky.bluesky.utils;
    
    import android.content.Context;
    import android.graphics.Rect;
    import android.text.TextUtils;
    import android.util.AttributeSet;
    import android.widget.TextView;
    
    /**
     * 跑马灯效果 textview                              
     * @author  zbtu
     * @date    2013-4-22 上午8:55:44                                                              
     */
    public class MarqueeTextView extends TextView
    {
        public MarqueeTextView(Context context)
        {
            this(context, null);
        }
        
        public MarqueeTextView(Context context, AttributeSet attrs)
        {
            super(context, attrs);
            
            setFocusable(true);
            setFocusableInTouchMode(true);
            
            setSingleLine();
            setEllipsize(TextUtils.TruncateAt.MARQUEE);
            setMarqueeRepeatLimit(-1);
        }
        
        public MarqueeTextView(Context context, AttributeSet attrs, int defStyle)
        {
            super(context, attrs, defStyle);
            
            setFocusable(true);
            setFocusableInTouchMode(true);
            
            setSingleLine();
            setEllipsize(TextUtils.TruncateAt.MARQUEE);
            setMarqueeRepeatLimit(-1);
        }
    
        @Override
        protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect)
        {
            if (focused)
            {
                super.onFocusChanged(focused, direction, previouslyFocusedRect);
            }
        }
        
        @Override
        public void onWindowFocusChanged(boolean focused)
        {
            if (focused)
            {
                super.onWindowFocusChanged(focused);
            }
        }
        
        @Override
        public boolean isFocused()
        {
            return true;
        }
    }

    因为已经做了焦点等处理,所以不用再配置

    android:ellipsize="marquee"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:gravity="center_vertical"
    android:marqueeRepeatLimit="marquee_forever"

    直接引用即可

  • 相关阅读:
    Passion回来了
    VS.NET Addin在Design time获取控件值
    [过时的消息]VS2005 Shipped!
    为asp.net程序添加自定义配置区域
    Visual Studio .NET 2002 Service Pack 1 出来了
    Winform下通过控件名称来获取控件
    new blog, new life
    我的hotmail信箱容量变成2G了!
    first day in microsoft
    在client端通过java script调用Web Service
  • 原文地址:https://www.cnblogs.com/anee/p/3039959.html
Copyright © 2011-2022 走看看