Android textview 跑马灯文字滚动效果

2015-06-04 0 481
Android textview 跑马灯文字滚动效果

设置如下TextView控件文件的XML:

<com.example.Mytext
        android:id="@+id/textview" 

        android:layout_width="match_parent"

        android:layout_height="20dp"

        android:gravity="center"

        android:singleLine="true"//限制行数为1行

        android:ellipsize="marquee"//marquee 文字滚动

        android:marqueeRepeatLimit="marquee_forever"//文字滚动次数:marquee_forever 无限次

        android:focusable="true"//获取焦点

        android:focusableInTouchMode="true"//获取触摸焦点

        android:textColor="@color/red"

        android:text="@string/text"
         />

有其它布局如ScrollView等抢占焦点,需要自定义控件获取焦点:

public class Mytext extends TextView {  
public Mytext(Context context, AttributeSet attrs) {  
super(context, attrs);  
    } 
@Override
protected void onFocusChanged(boolean focused, int direction,
Rect previouslyFocusedRect) {
if(focused){  
super.onFocusChanged(focused, direction, previouslyFocusedRect);

     }
}
@Override  
public void onWindowFocusChanged(boolean hasWindowFocus) {  
if(hasWindowFocus){  
super.onWindowFocusChanged(hasWindowFocus); 

     } 

}  

@Override  

public boolean isFocused() {  

return true;  

     }  

}

遇见资源网 java Android textview 跑马灯文字滚动效果 http://www.ox520.com/9399.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务