| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
10年前发布

真正的TextView跑马灯

android自带的跑马灯是必须在有焦点的情况下才会滚动,一旦失去焦点跑马灯就会失去效果。

现在我的做法是自定义TextView 并重写isFocusedonFocusChanged方法,设置focused为true,这样TextView就可以始终获取到焦点

亲测可用!

1。自定义TextView:

</div> </div>
    import android.content.Context;        import android.graphics.Rect;        import android.util.AttributeSet;        import android.view.ViewDebug.ExportedProperty;        import android.widget.TextView;                public class ScrollForeverTextView extends TextView        {                    public ScrollForeverTextView(Context context)            {                super(context);                // TODO Auto-generated constructor stub            }                    public ScrollForeverTextView(Context context, AttributeSet attrs,                    int defStyle)            {                super(context, attrs, defStyle);                // TODO Auto-generated constructor stub            }                    public ScrollForeverTextView(Context context, AttributeSet attrs)            {                super(context, attrs);                // TODO Auto-generated constructor stub            }                    @Override            @ExportedProperty(category = "focus")            public boolean isFocused()            {                // TODO Auto-generated method stub                return true;//重点            }                    @Override            protected void onFocusChanged(boolean focused, int direction,                    Rect previouslyFocusedRect)            {                // TODO Auto-generated method stub                super.onFocusChanged(true, direction, previouslyFocusedRect);//重点            }        }  

 

2。xml中引用:

    import android.content.Context;        import android.graphics.Rect;        import android.util.AttributeSet;        import android.view.ViewDebug.ExportedProperty;        import android.widget.TextView;                public class ScrollForeverTextView extends TextView        {                    public ScrollForeverTextView(Context context)            {                super(context);                // TODO Auto-generated constructor stub            }                    public ScrollForeverTextView(Context context, AttributeSet attrs,                    int defStyle)            {                super(context, attrs, defStyle);                // TODO Auto-generated constructor stub            }                    public ScrollForeverTextView(Context context, AttributeSet attrs)            {                super(context, attrs);                // TODO Auto-generated constructor stub            }                    @Override            @ExportedProperty(category = "focus")            public boolean isFocused()            {                // TODO Auto-generated method stub                return true;//重点            }                    @Override            protected void onFocusChanged(boolean focused, int direction,                    Rect previouslyFocusedRect)            {                // TODO Auto-generated method stub                super.onFocusChanged(true, direction, previouslyFocusedRect);//重点            }        }  
来自:http://blog.csdn.net/u012252502/article/details/30225929
</div>
    </div>

     本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
     转载本站原创文章,请注明出处,并保留原始链接、图片水印。
     本站是一个以用户分享为主的开源技术平台,欢迎各类分享!