开发者

Android - TextView scrolling

I would like to make a TextView scrolling automatica开发者_如何学Pythonlly 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜