Android 时钟可见时ScrollingTextView不工作
我的应用程序中有一个显示当前时间的文本视图,我是这样实现的Android 时钟可见时ScrollingTextView不工作,android,Android,我的应用程序中有一个显示当前时间的文本视图,我是这样实现的 private Handler handler = new Handler(); private Runnable runnable = new Runnable() { public void run() { batteryLevel(); if(clock_on == true) { Handler clockUpdate = new Handler(); cloc
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;
}
}
如果时钟文本视图可见,则ScrollingTextView不工作,当我使时钟的可见性消失时,ScrollingTextView工作正常
为什么会这样?
我怎样才能修好它
编辑:如果我延迟了ScrollingTextView开始工作的时钟,但是一旦时钟TextView设置为当前时间,ScrollingTextView就会停止工作
更新:经过一点测试后,我注意到ScrollingTextView正在工作,但每次executeClock()方法运行时,ScrollingTextView动画都会重置并再次启动您的clock textview和scrolltextview是否在同一个视图组中??例如,它们是否都是相同线性或相对布局的子视图??尝试将它们分开,并使它们成为不同视图组的子视图。这对我有用过一次,也可能对你有用时钟在主布局>中央>中央控制台中,滚动文本在主布局>lcd>lcd屏幕中
<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" />