laclac
laclac

Reputation: 31

Android - TextView scrolling

I would like to make a TextView scrolling automatically but I did not succeed (as marquee in html). Could you tell me how?

Best Regard

Upvotes: 3

Views: 4865

Answers (2)

paiego
paiego

Reputation: 3787

A TextView, with ellipsize set to "marquee", will not scroll unless it has the focus.

Are you looking for a marquee the scrolls regardless of the focus?

If so, you could use a TranslateAnimation with a LinearInterpolator to give it that consistent scrolling look. This is what I use and it works fine.

    DisplayMetrics dm = getResources().getDisplayMetrics();

    TranslateAnimation m_ta = new TranslateAnimation(dm.widthPixels, -1 * (dm.widthPixels), 0f, 0f);
    m_ta.setDuration(10000);
    m_ta.setInterpolator(new LinearInterpolator());
    m_ta.setRepeatCount(Animation.INFINITE);

    TextView m_tv = (TextView)findViewById(R.id.tvMarquee);
    m_tv.startAnimation(m_ta);

Upvotes: 5

Blumer
Blumer

Reputation: 5035

You'll want to look at the ellipsize property of the TextView and set it to "marquee". Here's the Android documentation.

Upvotes: 1

Related Questions