使用搜索栏和setProgress不会改变搜索栏的位置 [英] Using SeekBar and setProgress doesn't change seekBar position

查看:405
本文介绍了使用搜索栏和setProgress不会改变搜索栏的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的片段的搜索栏,并需要在搜索栏移动到不同的位置。然而,setProgress(XXX)不工作。你如何编程方式触发此方法对于搜索栏:公共无效onProgressChanged(搜索栏搜索栏,INT进步,布尔FROMUSER)?手动移动搜索栏工作正常。

I am using a seekbar in a fragment and need to move the seekbar to different positions. However, setProgress(xxx) is not working. How do you trigger this method programmatically for a seekbar: public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)? Moving the seekbar manually works fine.

推荐答案

这是在进度的一个Bug!

setProgress(...)似乎不触发的更新绘制如果同样的值再次通过。但它不是SETMAX期间触发了。所以更新是丢失。

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.

要解决这个问题,我只是在做一个 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.setProgress(0); // call these two methods before setting progress.
bar.setMax(20);
bar.setProgress(20);

第二个选项。

mSeekBar.post(new Runnable() {
        @Override
        public void run() {
            mSeekBar.setProgress(percentOfFullVolume);
        }
    });

这也可能适用于人。

it may also work for someone.

尝试先设置最大值,然后设置进度。

这篇关于使用搜索栏和setProgress不会改变搜索栏的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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