Android的进度不更新进度视图/绘制 [英] android progressBar does not update progress view/drawable

查看:205
本文介绍了Android的进度不更新进度视图/绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两间酒吧,显示游戏的进度。如果用户拿分或者时间到了等等的progressBars应该被更新:

two Bars which shows the progress of a game. If the user get points or time is up etc the progressBars should be updated:

private TextView tv;
private ProgressBar levelHoldBar;
private ProgressBar levelUpBar;

//...
private void updateViews() {

    // ...
    levelHoldBar.setMax(currentLevel.getThreshold());
    levelHoldBar.setProgress(currentPoints > currentLevel.getThreshold() ? currentLevel.getThreshold() : currentPoints);

    levelUpBar.setMax(nextLevel.getThreshold());
    levelUpBar.setProgress(currentPoints > nextLevel.getThreshold() ? nextLevel.getThreshold() : currentPoints);

    tv.setText(currentPoints+"/"+currentLevel.getThreshold());

    Log.d(TAG, "hold prog/max "+levelHoldBar.getProgress()+"/"+levelHoldBar.getMax());
    Log.d(TAG, "up   prog/max "+levelUpBar.getProgress()+"/"+levelUpBar.getMax());
}

IE浏览器。输出:

ie. Outputs:

12-03 17:48:33.918: DEBUG/MainActivity(6829): hold prog/max 20/20
12-03 17:48:33.918: DEBUG/MainActivity(6829): up   prog/max 20/50

在Log.d(...)到底显示的总是正确的价值观,但有时的progressBars的视觉条不显示正确的进度变化。它们表明,已被设置previously进展即使吸气剂为最大和进步返回正确的值(本例中的条显示(约20%,而不是100%)为levelHoldBar和大约2%(而不是40%)的的LevelUp杆)。我想不通,为什么日志输出是正确的,但在可绘就错了!? TextView的(电视)正确更新!发生了什么?我该如何解决呢?

The Log.d(...) in the end shows ALWAYS the correct values, but SOMETIMES the visual bars of the progressBars do not show the correct progesses. They show progresses that had been set previously even if the getters for "max" and "progress" return correct values (in the example the bar shows about 20% (instead of 100%) for the levelHoldBar and about 2% (instead of 40%) for the levelUp-bar). I cannot figure out, why the log-output is correct but the drawables are wrong!? The TextView (tv) is updated correctly! Whats going on here? How can I fix that?

推荐答案

解决方案::这是在进度的一个Bug

SOLUTION: It's a Bug in ProgressBar!

终于......我想我找到了解决办法...

finally... I think I found the solution...

这不工作,人们所期望的:

this does not work as one would expect:

bar.setMax(50);
bar.setProgress(20);
bar.setMax(20);
bar.setProgress(20);

的setProgress(...)似乎不会触发对被拉伸的更新,如果相同的值再次通过。但它不是在SETMAX过程中触发了。所以更新是丢失。好像在android进度的一个Bug!这花了我现在的约8小时..大声笑:D

The setProgress(...) seems to not trigger the update on the drawable if the same value is passed again. But it's not triggered during the setMax, too. So the update is missing. Seems like a Bug in the android ProgressBar! This took me about 8 hours now.. lol :D

要解决这个问题,我只是在做一个bar.setProgress(0)每次更新前......这仅仅是一个解决办法,但它为我的预期:

To solve this, I'm just doing a bar.setProgress(0) before each update... this is only a workaround, but it works for me as expected:

bar.setMax(50);
bar.setProgress(20);
bar.setProgress(0); // <--
bar.setMax(20);
bar.setProgress(20);

这篇关于Android的进度不更新进度视图/绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆