If you ever need to change the height of your Seekbar you may find that the thumb is not centering properly.
The fix for this is actually pretty simple. It just took me a while to find, so i’m posting this in the hopes of helping fellow developers cut down on their search time.
After trying things like gravity and margins and such with no success, i wondered well how the heck does android do it anyway?
That led me to seeing how they define their default seekbar style.
- false
- @android:drawable/progress_horizontal
- @android:drawable/progress_horizontal
- 20dip
- 20dip
- @android:drawable/seek_thumb
- 8dip
- true
Which i then compared to mine.
- fill_parent
- 60dp
- @drawable/slider_thumb
- @drawable/seekbar
What immediately caught my eye was the minHeight and maxHeight attributes. It’s possible that when this widget is being laid out android takes these values into account so I tried it.
- fill_parent
- 60dp
- 60dp
- 60dp
- @drawable/slider_thumb
- @drawable/seekbar
Lo and behold it worked!
So what’s the answer?
If you need to adjust the height of your seekbar make sure you define the minHeight and maxHeight attributes or your Seekbar because android takes them into account when placing the thumb.
8 comments on “Android: How to fix Seekbar bar thumb centering issues.”