android - 可运行线程导致图像按钮边距“重置”
问题描述
可运行线程调用导致 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);
}
};
解决方案
推荐阅读
- xslt - XSLT 转换未正确映射
- linux - 使用 vconfig 添加 vlan 时出现“设备或资源繁忙”
- javascript - 在行悬停时显示最后一个表格列
- android - 如何在android相机api上进行图像分析
- android - java.lang.IllegalArgumentException 在 Android 10 设备中找不到卷 external_primary
- javascript - Vue Chart.js - 使极地区域图在悬停时改变颜色
- java - POI读取带有字符串正文的Excel文件
- c - 使用 UART 时的串行端口通信问题
- typescript - Passport Azure AD 此表达式不可调用
- python-3.x - 无法使用带有 python 3.8 的 conda 安装 tensorflow