Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to limit seekbar

I'd like to set max and minimum limits of SeekBar to 50 and 20 respectively.

SeekBar has a direct option top provide max value, but how to set its minimum value to 20 rather than 0?

like image 859
Shishir.bobby Avatar asked Aug 16 '10 06:08

Shishir.bobby


People also ask

How do I set the value of SeekBar?

One possible solution would be to set seekBar. setMax(20) (or android:max="20" in XML), and whenever you use or display the value, multiply it by 10. The SeekBar would then appear to move at least 20 at a time.

How do you set max and min in SeekBar?

In order to set the max value in java file you can use the function setMax(INTEGER) on seekbar object to set the max value. seekBar = (SeekBar) findViewById(R. id. seekBar1); seekBar.

How do I manage SeekBar on android?

Below are the steps for Creating SeekBar Android Application: Step1: Create a new project. After that, you will have java and XML file. Step2: Open your xml file and add a SeekBar and TextView for message as shown below, max attribute in SeekBar define the maximum it can take.

How do I change SeekBar thickness?

You can use the Slider provided by the Material Components Library. Use the app:trackHeight="xxdp" (the default value is 4dp ) to change the height of the track bar. It requires the version 1.2. 0 of the library.


1 Answers

In SeekBar you can set only max value.

<SeekBar android:id="@+id/SeekBar01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:max="50"/> 

And, You cannot directly set the minimum value to the seekbar.

 SeekBar mSeekbar = (SeekBar) findViewById(R.id.SeekBar01);      mSeekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListener()     {        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)        {             length_edit.setText(Integer.toString(progress + 20));        }        public void onStartTrackingTouch(SeekBar seekBar) {}        public void onStopTrackingTouch(SeekBar seekBar) {}     }); 

As you see min progress you can sum with min which I would like - in your case 20.

like image 99
Paresh Mayani Avatar answered Sep 28 '22 05:09

Paresh Mayani