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

一笑奈何 提交于 2019-11-28 04:43:51

问题


I want to customize the SeekBar as shown below in the image.

I'm a beginner in programming and I looked for tutorials, but every where the progress starts in the leftmost corner. Can someone please guide me how can I customize the SeekBar.

So In onProgresschanged.

 @Override
 public void onProgressChanged(SeekBar seekBar,int progress, boolean fromUser) {            
brightness = progress;
    putGestureImageOnScreen(doBrightness(imageBitmap, brightness));
 }

Thanks.


回答1:


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.




回答2:


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




回答3:


place this in Oncreate

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



回答4:


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



回答5:


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



来源:https://stackoverflow.com/questions/22034252/how-do-i-make-a-seekbar-whose-initail-progress-which-is-zero-starts-in-the-midd

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