开发者

Android - TextView scrolling

开发者 https://www.devze.com 2023-02-02 17:21 出处:网络
I would like to make a TextView scrolling automatica开发者_如何学Pythonlly but I did not succeed

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

精彩评论

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