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
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);
You'll want to look at the ellipsize
property of the TextView and set it to "marquee". Here's the Android documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.