WEB开发网
开发学院手机开发Android 开发 ScrollTextView - scrolling TextView for Androi... 阅读

ScrollTextView - scrolling TextView for Android

 2010-04-13 21:01:00 来源:WEB开发网   
核心提示:setSingleLine();setEllipsize(null);setVisibility(INVISIBLE);}/*** begin to scroll the text from the original position*/public void startScroll() {// begin from

setSingleLine();

setEllipsize(null);

setVisibility(INVISIBLE);

}

/**

* begin to scroll the text from the original position

*/

public void startScroll() {

// begin from the very right side

mXPaused = -1 * getWidth();

// assume it's paused

mPaused = true;

resumeScroll();

}

/**

* resume the scroll from the pausing point

*/

public void resumeScroll() {

if (!mPaused)

return;

// Do not know why it would not scroll sometimes

// if setHorizontallyScrolling is called in constructor.

setHorizontallyScrolling(true);

// use LinearInterpolator for steady scrolling

mSlr = new Scroller(this.getContext(), new LinearInterpolator());

setScroller(mSlr);

int scrollingLen = calculateScrollingLen();

int distance = scrollingLen - (getWidth() + mXPaused);

int duration = (new Double(mRndDuration * distance * 1.00000

/ scrollingLen)).intValue();

setVisibility(VISIBLE);

mSlr.startScroll(mXPaused, 0, distance, 0, duration);

mPaused = false;

}

/**

* calculate the scrolling length of the text in pixel

*

* @return the scrolling length in pixels

*/

private int calculateScrollingLen() {

TextPaint tp = getPaint();

Rect rect = new Rect();

String strTxt = getText().toString();

tp.getTextBounds(strTxt, 0, strTxt.length(), rect);

int scrollingLen = rect.width() + getWidth();

rect = null;

return scrollingLen;

}

/**

* pause scrolling the text

*/

public void pauseScroll() {

if (null == mSlr)

Tags:ScrollTextView scrolling TextView

编辑录入:coldstar [复制链接] [打 印]
赞助商链接