ScrollTextView - scrolling TextView for Android
2010-04-13 21:01:00 来源:WEB开发网找了很就终于在国外一网站上找到一个Scroller的例子,为了日后方便查阅,在博客上记录以下。
Here are the source codes.
The key points are:
setHorizontallyScrolling() and use android.widget.Scroller to make the text scroll;
Use the attached TextPaint of the TextView to measure the length of the text in pixel;
setSingleLine() and setEllipsize(null) to make the text not wrapped and ellipsized;
Override computeScroll() to restart the scrolling when finished
Here are the source codes.
代码
/*************************************************************************/
package com.dirtybear.android;
import android.content.Context;
import android.graphics.Rect;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.animation.LinearInterpolator;
import android.widget.Scroller;
import android.widget.TextView;
public class ScrollTextView extends TextView {
// scrolling feature
private Scroller mSlr;
// milliseconds for a round of scrolling
private int mRndDuration = 250;
// the X offset when paused
private int mXPaused = 0;
// whether it's being paused
private boolean mPaused = true;
/*
* constructor
*/
public ScrollTextView(Context context) {
this(context, null);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs) {
this(context, attrs, android.R.attr.textViewStyle);
}
/*
* constructor
*/
public ScrollTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// customize the TextView
Tags:ScrollTextView scrolling TextView
编辑录入:coldstar [复制链接] [打 印]更多精彩
赞助商链接