Question

I want to customize the SeekBar as shown below in the image.Make a seekbar like this one

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top