0

textview通过在 xml 中提供属性来创建选取框。但是当我textview在运行时创建时with the same property,文本不会滚动。我写了下面的代码。有人遇到这个问题吗?

 TextView textView = new TextView(this);
 textView.setText("This is marquee text it should scroll");
 textView.setEllipsize(TruncateAt.MARQUEE);
 textView.setFocusableInTouchMode(true);
 textView.setFreezesText(true);
 textView.setSingleLine(true);
 textView.setMarqueeRepeatLimit(-1);
 textView.setFocusable(true);
 textView.setSelected(true);
4

3 回答 3

1

I tested your code on my Galaxy Nexus (working on Jelly Bean), and it works fine. Could you give more detail information about your test setting?

Ah, one thing I added is layout param to ensure the width of view is shorter than text itself.

    textView.setLayoutParams(new ViewGroup.LayoutParams(100,
    ViewGroup.LayoutParams.MATCH_PARENT));
于 2013-08-21T10:18:29.503 回答
1
    Animation mAnimation = new TranslateAnimation(START_POS_X, END_POS_X, 
                START_POS_Y, END_POS_Y);
mAnimation.setDuration(TICKER_DURATION); 
mAnimation.setRepeatMode(Animation.RESTART);
mAnimation.setRepeatCount(Animation.INFINITE);

        TextView tvTitulo = new TextView(this);
        tvTitulo.setText("Some loooooooooooooooooooooong text");
        tvTitulo.setAnimation(mAnimation);


jUST CHECK this code .....
于 2013-08-21T10:25:08.933 回答
0

添加这个,

textView.setHorizontallyScrolling(true);

试试这个,它可以帮助你

android:maxLines = "AN_INTEGER"
android:scrollbars = "vertical"

//........
于 2013-08-21T10:14:00.130 回答