0

我的应用程序中有一个显示当前时间的 TextView,我是这样实现的

private Handler handler = new Handler();


private Runnable runnable = new Runnable() 
{

public void run() 
{
   batteryLevel();
     if(clock_on == true) {


         Handler clockUpdate = new Handler(); 
         clockUpdate.postDelayed(new Runnable() { 
              public void run() {
                  executeClock();
              } 
         }, 500);



     }
     handler.post(this);






}

public void executeClock() {



    TextView timeTv = (TextView) findViewById(R.id.time);

    long currentTime=System.currentTimeMillis();
    Calendar cal=Calendar.getInstance();
    cal.setTimeInMillis(currentTime);
    String timeFormat24 = "%1$tH:%1$tM";   
 //   String timeFormat12 = "%1$tI:%1$tM";
    String showTime=String.format(timeFormat24,cal);
    timeTv.setText(showTime);


}

在我的应用程序中,我也有一个 ScrollingTextView,ScrollingtextView.java

public class ScrollingTextView extends TextView {

public ScrollingTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public ScrollingTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public ScrollingTextView(Context context) {
    super(context);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    if(focused)
        super.onFocusChanged(focused, direction, previouslyFocusedRect);
}

@Override
public void onWindowFocusChanged(boolean focused) {
    if(focused)
        super.onWindowFocusChanged(focused);
}


@Override
public boolean isFocused() {
    return true;
}

}

<com.doublep.example.ScrollingTextView
            android:id="@+id/txt_lcd_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:ellipsize="marquee"
            android:marqueeRepeatLimit="marquee_forever"
            android:scrollHorizontally="true"
            android:singleLine="true"
            android:textColor="#f82424"
            android:textSize="30dp" />

如果时钟 TextView 可见,则 ScrollingTextView 不起作用,当我使时钟的可见性消失时,ScrollingTextView 工作正常

为什么会这样?我该如何解决?

编辑:如果我延迟 ScrollingTextView 开始工作的时钟,但是一旦时钟 TextView 设置为当前时间,则 ScrollingTextView 停止工作

更新:经过一些测试后,我注意到 ScrollingTextView 正在工作,但是每次 executeClock() 方法运行时,ScrollingTextView 动画都会重置并再次开始

4

1 回答 1

0

Do you have your clock textview and scrolltextview in the same viewgroup?? so for example are they all child views of the same linear or relative layout?? Try to separate them and make them child of different viewgroups. That worked for me once and may work for you too

于 2012-09-18T22:18:20.943 回答