Android SeekBar 抖动

发布于 2024-11-19 10:30:55 字数 795 浏览 3 评论 0原文

我还没有看到这个问题被报道过,所以就这样吧。我有一个搜索栏,可以防止搜索超出次要进度(在本例中为音乐缓冲)。假设这首歌长 5 分钟,已缓冲 4 分​​钟,并且正在一分钟标记处播放。当我去拖动拇指时,它会很好地拖动和下降。问题是,当我停止拖动(不释放)然后再次拖动时,拇指会从当前播放位置(1 分钟)快速跳到我拖动拇指的位置。当我释放时,一切都很好,只是拖动拇指的问题。这是我的搜索栏监听器......

private SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {

    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {

        int secondaryPosition = seekBar.getSecondaryProgress();
        if (progress > secondaryPosition) {
            seekBar.setProgress(secondaryPosition-1);
        }
    }

    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        seekMediaPlayerToSeekBarTouch(seekBar);
    }

};

I haven't seen this issue covered on SO so here it goes. I have a seekbar that prevents seeking beyond the secondary progress(in this case, music buffering). Let's say the song is 5 minutes long, 4 minutes have been buffered, and it is playing at the one minute mark. When I go to drag the thumb, it drags and drops fine. The issue is that when I stop dragging(without releasing) and then drag again, the thumb is rapidly jumping from the currently playing position(1 minute) to the position I am dragging the thumb. When I release, it's fine, it's only an issue with dragging the thumb. Here is my seekbar listener....

private SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {

    public void onProgressChanged(SeekBar seekBar, int progress,
            boolean fromUser) {

        int secondaryPosition = seekBar.getSecondaryProgress();
        if (progress > secondaryPosition) {
            seekBar.setProgress(secondaryPosition-1);
        }
    }

    public void onStartTrackingTouch(SeekBar seekBar) {

    }

    public void onStopTrackingTouch(SeekBar seekBar) {
        seekMediaPlayerToSeekBarTouch(seekBar);
    }

};

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随风而去 2024-11-26 10:30:55

我猜您有一个 HandlerThread 来更新 SeekBar?我建议设置一个基本检查来查看用户是否正在处理 SeekBar,这样它就不会在处理时不断尝试重绘 SeekBar 的拇指。只需在 onStartTrackingTouch() 方法中设置一个布尔值,例如将 mSeekbarTracking 设置为 true,然后在 SeekBar 更新程序中检查 mSeekbarTracking 在尝试更新之前为 false。

我不知道这是否能解决你所有的问题。也许您可以尝试一下,看看它如何影响您的问题。如果您发布用于更新 SeekBar 的代码,这可能会对我们有所帮助。

干杯

I'm guessing you have a Handler or a Thread to update the SeekBar? I would recommend setting up a basic check to see if the user is handling the SeekBar so it won't keep trying to redraw the thumb for the SeekBar while it's being handled. Just set a boolean, such as mSeekbarTracking to true in the onStartTrackingTouch() method, then in the SeekBar updater, make it check that mSeekbarTracking is false before it tries to update it.

I don't know if that will solve all of your problems though. Maybe you could try that and see how it affects your issue. It will probably help us help you if you post the code that you're using to update the SeekBar.

Cheers

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文