zoukankan      html  css  js  c++  java
  • android实现跑马灯效果(能够实现两个以上跑马灯)

    本文用了继承自TextView的MarqueeTextView来实现跑马灯效果。原因是,跑马灯效果是须要TextView拥有焦点才会跑动的。而有时候TextView获得焦点会有点耗时,造成要等待一段时间跑马灯效果才会出来。

    另外。系统默认是仅仅有一个TextView处于focused状态,而当页面有不少于两个跑马灯时,用TextView就不好实现了。



    MarqueeTextView类代码:

    public class MarqueeTextView extends TextView{
    
    	public MarqueeTextView(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		// TODO Auto-generated constructor stub
    	}
    	
    	@Override
    	protected void onFocusChanged(boolean focused, int direction,
    			Rect previouslyFocusedRect) {
    		// TODO Auto-generated method stub
    		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布局文件相关代码:

    <com.barry.components.MarqueeTextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.0"
        android:ellipsize="marquee"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:freezesText="true"
        android:marqueeRepeatLimit="marquee_forever"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:scrollHorizontally="true"
        android:singleLine="true" />
    <!--width设为详细大小也行。--!>




  • 相关阅读:
    中国软件技术篇
    create pdf
    我来了
    补丁号
    rdlc里面用VB语法对数值型数据进行Format
    WinForm中有些控件不能添加ToolTip关联的解决方法
    javascript弹出对话框
    省市县关联菜单
    委托与事件
    ASP.NET多文件上传方案
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6856924.html
Copyright © 2011-2022 走看看