Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You have to create a custom class for scrolling the text:</p> <p>ScrollTextView.java</p> <pre><code>public class ScrollTextView extends TextView { // scrolling feature private Scroller mSlr; // milliseconds for a round of scrolling private int mRndDuration = 10000; // 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); // customize the TextView setSingleLine(); setEllipsize(null); setVisibility(INVISIBLE); } /* * constructor */ public ScrollTextView(Context context, AttributeSet attrs) { this(context, attrs, android.R.attr.textViewStyle); // customize the TextView setSingleLine(); setEllipsize(null); setVisibility(INVISIBLE); } /* * constructor */ public ScrollTextView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // customize the TextView 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); invalidate(); 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) return; if (mPaused) return; mPaused = true; // abortAnimation sets the current X to be the final X, // and sets isFinished to be true // so current position shall be saved mXPaused = mSlr.getCurrX(); mSlr.abortAnimation(); } @Override /* * override the computeScroll to restart scrolling when finished so as that * the text is scrolled forever */ public void computeScroll() { super.computeScroll(); if (null == mSlr) return; if (mSlr.isFinished() &amp;&amp; (!mPaused)) { this.startScroll(); } } public int getRndDuration() { return mRndDuration; } public void setRndDuration(int duration) { this.mRndDuration = duration; } public boolean isPaused() { return mPaused; } } </code></pre> <p>In your layout write like this:</p> <pre><code>&lt;yourpackagename.ScrollTextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/scrolltext" /&gt; </code></pre> <p>In your activity write like this:</p> <pre><code>ScrollTextView scrolltext=(ScrollTextView) findViewById(R.id.scrolltext); scrolltext.setText(yourscrollingtext); scrolltext.setTextColor(Color.BLACK); scrolltext.startScroll(); </code></pre> <p>If you want to increase the scrolling speed then reduce the value of :</p> <pre><code>private int mRndDuration = 10000;//reduce the value of mRndDuration to increase scrolling speed </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload