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

ScrollTextView - scrolling TextView for Android

 2010-04-13 21:01:00 来源:WEB开发网   
核心提示:找了很就终于在国外一网站上找到一个Scroller的例子,为了日后方便查阅,ScrollTextView - scrolling TextView for Android,在博客上记录以下,Here are the source codes.The key points are:setHorizontallyScrol

找了很就终于在国外一网站上找到一个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

1 2 3  下一页

Tags:ScrollTextView scrolling TextView

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读