Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 957
laclac Avatar asked Dec 08 '25 09:12

laclac


1 Answers

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);
like image 187
paiego Avatar answered Dec 09 '25 21:12

paiego



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!