首页 > 解决方案 > 可运行线程导致图像按钮边距“重置”

问题描述

可运行线程调用导致 imagebutton 属性“重置”

我有一个计时器在文本框中工作正常。每一秒都在计数。我有一个图像按钮,当我单击它时,上边距会上升以显示它已被选中。计时器的可运行调用使图像按钮不会向上移动。如果我评论呼叫,则图像按钮会在单击时再次向上移动。

有问题的代码行...

customHandler.postDelayed(updateTimerThread, 0);

当被注释掉时,imagebutton 的行为是我希望它在点击时的行为,setTop(-30)。效果很好。

如果我取消注释上述行,则 imagebutton 不会向上移动。当我调试 setTop(-30) 行时,确实被命中并且没有抛出错误。

更新定时器线程...

private Runnable updateTimerThread = new Runnable() { 
    public void run() { 
        timeInMilliseconds = SystemClock.uptimeMillis() - startTime; 
        updatedTime = timeSwapBuff + timeInMilliseconds;
        int secs = (int) (updatedTime / 1000);
        int mins = secs / 60;
        secs = secs % 60;
        textTimer.setText(String.format("%02d", mins) + ":" + String.format("%02d", secs)); 
        customHandler.postDelayed(this, 0);
    } 
};

标签: androidimagebutton

解决方案


推荐阅读