Is there a function (or an XML tag) which allows to change the width of thumb in the seekBar dynamically , when the maxValue is changed . For example if the maxValue == 2 the Thumb takes the half of the whole Seekbar , then if maxValue is 3 , it takes the 1/3-th of the width , and so on .
3 Answers
The SeekBar thumb can only be set in XML, not dynamically. What you are looking for is akin to a scrollbar. Views which are scrollable, like ListView, have these built in, so you don't need to do anything.

- 858
- 8
- 10
-
Iam using SeekBar for scrolling the `HorizontalScrollView` . Is there a way to set the scrollbar separately from scrollView ? – user3199577 Jan 28 '14 at 10:53
-
As far as I know, the HorizontalScrollView has its own scrollbars. Why are you trying to duplicate this functionality by adding a SeekBar? – katzoft Jan 28 '14 at 11:46
-
is there a margin for scrollbar , I dont want it to take all the width of the scrollView ? or can I change the design of the scrollbar ? – user3199577 Jan 28 '14 at 14:21
-
You can influence the look and feel of the scrollbar using themes and styles. – katzoft Jan 28 '14 at 14:39
You need to programatically implement the logic..by using thumsize and progress values and implementing OnSeekBarChangeListener
You can ask if you have any further queries :)

- 2,129
- 2
- 17
- 27
-
-
-
Something changed , and I dont understand what exactly . But I didn't get what I wanted :) – user3199577 Jan 28 '14 at 11:02
-
-
setThumbOffset sets how much of the thumb can go off the end of the track - it assumes you have a symmetrical thumb drawable, but if you don't you can line up your drawable & track – FunkTheMonk Feb 03 '14 at 19:14
If you're targeting only android devices running v16+, you might be able to do this using getThumb().setBounds()
, but doing so may have consequences if you do it whilst the user is touching the view.
You will also want to update the offset using setThumbOffset()
passing in 1/2 the width of the new bounds.
You can also just replace the thumb with a new drawable, which will update the offset for you (if you have a symmetrical drawable), but adjust its bounds is probably going to be more efficient.

- 10,908
- 1
- 31
- 37