user1000594
user1000594

Reputation: 131

How to change Android SeekBar track start position?

I'd like to set the SeekBars's track start position so it does not start from the left side of the seekbar, but form an arbitrary position. Here is a photoshop image how it should look like:

http://i.imgur.com/QCMEu.png

It should be just a graphical effect, the SeekBar's underlying logic is not changed.

I tried to change the Seekbar.getprogressDrawable.SetBounds() to change the track image position, but no luck.

Upvotes: 13

Views: 31256

Answers (6)

Hiral Vadodaria
Hiral Vadodaria

Reputation: 19250

You can set progress of SeekBar in xml as:

android:progress="10"
android:max="90" <!-- maximum seekbar progress -->

you can programmatically set the progress of SeekBar as:

seekBar.setProgress(10);

Upvotes: 8

Aviad Klein
Aviad Klein

Reputation: 23

You can add this: android:rotation="180" to the XML and then the seekbar will flip the way you want

Upvotes: 1

Maksim Golendukhin
Maksim Golendukhin

Reputation: 144

Just faced the same problem. That's how I have solved it.

Assume, we need seekbar starting from 10 and ending at 150.

@Override
    protected void onCreate(Bundle savedInstanceState)
    {...
     yourSpinner = (Spinner) findViewById(R.id.your_spinner);
     yourSpinner.setMax(150 - 10);

     int newProgress;

     yourSpinner.setOnSeekBarChangeListener(new   SeekBar.OnSeekBarChangeListener()
        {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser)
            {
                newProgress= 10 + progress;

                Toast.makeText(getApplicationContext(), String.valueOf(newProgress), Toast.LENGTH_LONG).show();
            }
        });
    }

Upvotes: 0

Gaurav Vashisth
Gaurav Vashisth

Reputation: 7737

May be your problem is similar to Seekbar for two values [-50, 0, 50].

Thanks to Commonsware to point to right direction. I wrote a class inspired by code.google.com/p/range-seek-bar) to get the solution.

https://github.com/vashisthg/StartPointSeekBar

Upvotes: 3

Dhasneem
Dhasneem

Reputation: 4017

By Programatically,we can start the progress and set the maximum of seekbar progress.

//start from <starting value>
seekBar.setProgress(<strating_value>);

//Set to maximum Value<max_value>
seekBar.setMax(<max_value>);

Upvotes: 1

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

add this proprety

 android:progress="2" 

Upvotes: 10

Related Questions