TextView字幕和数字时钟



当我使用Digital clocktextview 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*/

我可以不同时使用两者吗?或者有什么解决方案吗?

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

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

2.设置DigitalClockHeightWidth

试试下面的代码,这对我来说很好

   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);

PSDigitalClock 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

最新更新