android progressBar does not update progress view/drawable

后端 未结 15 2270
悲哀的现实
悲哀的现实 2020-11-28 09:11

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 Progre         


        
相关标签:
15条回答
  • 2020-11-28 10:13

    Create updateThumb(); method in VerticalSeekbar

    public void updateThumb(){
         onSizeChanged(getWidth(), getHeight(), 0, 0);
    }
    

    And then call update thumb method after setting progress.

    seekBar.setProgress((int) progress);
    seekBar.updateThumb();
    

    its work for me in verticalseekbar calss

    0 讨论(0)
  • 2020-11-28 10:13

    everyone. in case of the exist progress and the new progress value is same, the progressbar is not update. so you set the new value as the near value, that is easy way.

    @Override
    public synchronized void setProgress(int progress)
    {
        if (getProgress() == progress)
        {
            if (progress > 0)   progress -= 1;
            else                progress += 1;
        }
    
        super.setProgress(progress);
    }
    
    0 讨论(0)
  • 2020-11-28 10:15

    Thanks Stuck for the post stating that there is an Android bug. I also have a vertical seek bar.

    The issue was when I was changing the progress drawable. The drawable would be updated but the bar would be set to 0 and be a very small size. I was able to get it to resize with updateThumb(), but the progress was still at 0.

    To set the progress back at the original value I added a mylayer.setLevel(...);. I found this by reading the source code of ProgressBar.doRefreshProgress(...). You might be able to do seekBar.getProgressDrawable.setLevel(...).

    LayerDrawable mylayer = //new LayerDrawable()
    seekBar.setProgressDrawable(mylayer);
    seekBar.updateThumb();
    seekBar.setProgress((int) chLevel);
    mylayer.setLevel((int) (chLevel / MAX_LEVEL * 10000));
    
    0 讨论(0)
提交回复
热议问题