Android: How to fix Seekbar bar thumb centering issues.

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!
centered

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.”

  1. Rikki

    Thanks for sharing. i was looking the exact thing. I also want to move the seekbar thumb to secondaryprogress instead of progress. Can I do so?? Much appreciated help needed

  2. noslen

    Hi Rikki,
    I’m not sure if I’m clear on what you’re asking for. It sounds like you just don’t want to progress to be there? just the secondary progress?
    You can be tricky and just make them both the same color. or make the progress bar transparent.
    Hope that helps, let me know if that’s not what you’re looking for.

  3. pankaj

    i have same problem but where i have to put this code

  4. vidushi

    HI i am trying to do this in the Layout xml file itself, and not creating any additional file for style. When i add minHeight & maxWeight, my seekbar height increases automatically, Why this is occuring? Please advice

  5. Tro Le

    @pankaj: you copy: android:minHeight=”13dp”
    android:maxHeight=”13dp” to your seekbar in xml layout file :)

  6. Chris

    Huge. Great. Awesome !
    Thank you so much.

Leave a Reply

Your email address will not be published. Required fields are marked *