0

当我使用Digital clockandtextview marquee时,textview marquee它不起作用 - 如果我删除数字时钟,它会完美运行。

 TextView tv = new TextView(this);

    tv.setLayoutParams(paramsSong);     
    tv.setEllipsize(TruncateAt.MARQUEE);
    tv.setFocusableInTouchMode(true);
    tv.setFreezesText(true);
    tv.setSingleLine(true);
    tv.setMarqueeRepeatLimit(-1);
    tv.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    tv.setSelected(true);
            rl.addView(tv);

    DigitalClock dg = new DigitalClock(this);
            rl.addView(dg);

/*if I remove digital clock then it works*/

我不能同时使用两者还是有什么解决方案?

4

1 回答 1

3

是的,您可以使用这些,但首先要纠正您的错误

1.您正在添加视图 rl.addView(tv);2 次

2. set Heightand WidthofDigitalClock

尝试以下对我来说很好的代码

   TextView tv = new TextView(this);
    rl.addView(tv);// Here is Your Mistake ! Remove it 
    tv.setLayoutParams(paramsSong);     
    tv.setEllipsize(TruncateAt.MARQUEE);
    tv.setFocusableInTouchMode(true);
    tv.setFreezesText(true);
    tv.setSingleLine(true);
    tv.setMarqueeRepeatLimit(-1);
    tv.setText("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
    tv.setSelected(true);
            rl.addView(tv);// Adding view Here is Absolutely Right ! 

    DigitalClock dg = new DigitalClock(this);
    dg.setHeight(setHeightHere);
    dg.setWidth(setWidthHere);
            rl.addView(dg);

PS。 DigitalClock class was deprecated in API level 17

文档http://developer.android.com/reference/android/widget/DigitalClock.html

This class was deprecated in API level 17.
It is recommended you use TextClock instead.

http://developer.android.com/reference/android/widget/TextClock.html

于 2013-08-26T09:59:02.510 回答