How do I make a seekbar whose initail progress which is zero, starts in the middle

蹲街弑〆低调 提交于 2019-11-29 10:51:10

Seekbars in Android cannot have negative values. Assuming you have specified a value of '100' for your maximum range of the progress bar (for example using setMax(100) or in your xml file using android:max="100"), then you can use this method to move your progress bar to the middle whenever you want (for example in your Activity.onCreate() or wherever else)

    yourProgressBar.setProgress(50);

After that you can get the progress value using:

    int progress = yourProgressBar.getProgress();

If you want to have a progress value between (e.g.) -50 to +50, then you can simply use:

    int progress = yourProgressBar.getProgress();
    progress -= 50;

Good luck.

AFAIK SeekBar with negative value is not possible in Android. For this take Your SeekBar bar range from 0 to 100. You can set it like..

seekbar.setMax(100);

initially start from the center like..

seekbar.setProgress(50);

And decrese it from the 50 to 0

place this in Oncreate

 seekBar=((SeekBar)(v.findViewById(R.id.seekBar1)));
    seekBar.setMax(100);
    seekBar.setProgress(50); 

I have written a blog about custom seekbar.You can look this.As Kalyan Said you need to set Max and progress of the seekBar.

seekbar.setMax(100);
seekbar.setProgress(50);//Set default progress of the Seekbar
nikhil_salunke

Through xml you can do it as : android:progress="20" means 20 is default position. Starting point of seek bar.

Or in your code you can do it like:

your_seekBar.setProgress(start_position);

ie. your_seekBar.setProgress(20)

you can adjust as you want

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!