How to make SeekBar take up full width of parent

11,521

Solution 1

Try to define following with the SeekBar in xml:

android:padding="0dp"

Solution 2

 android:paddingStart="0dp"
 android:paddingEnd="0dp"

Worked for me.

Solution 3

Just solved this problem in my app. The thing is, even though you didn't set the seekBar padding, there may be some paddings(paddingLeft, paddingTop, paddingRight, paddingBottom, paddingStart, paddingEnd) in the theme your appTheme extends. Set these paddings to 0dp, it should work fine.

Share:
11,521
David Heisnam
Author by

David Heisnam

Updated on June 20, 2022

Comments

  • David Heisnam
    David Heisnam almost 2 years

    I have a SeekBar in a RelativeLayout whose width is equal to the screen width.

    I applied layout_width="match_parent" to the SeekBar but it seems to keep some empty space on both sides of the SeekBar to accommodate the thumb.

    I also tried using android:thumb="@null" The thumb is gone but not the empty space on the sides.

    I really need to make the SeekBar width match the parent's. Could somebody help me with this? Maybe I could create a custom SeekBar class and set the width to the parent width in onMeasure(). If this is a possible solution, I don't know how I could pass the parent width to the SeekBar class.

    Any help is appreciated. Thank you.

  • David Heisnam
    David Heisnam over 9 years
    I have no paddings on the parent view. But thanks for your reply.
  • David Heisnam
    David Heisnam over 9 years
    I'm quite surprised that this actually worked! Thanks a lot. I would never have thought of this because I never expected any padding to be there unless I have specifically defined it in the layout.
  • Admin
    Admin over 8 years
    it doesn't work in API 17 or above stackoverflow.com/questions/33327246/…
  • temnoi
    temnoi over 7 years
    as @wrkwrk mentioned, if u put android:padding="0dp" android:paddingEnd="0dp" android:paddingStart="0dp" everything will work perfectly
  • Alon
    Alon about 4 years
    Had to specify android:paddingStart="0dp" and android:paddingEnd="0dp" for it to work
  • Sahbi
    Sahbi about 2 years
    This worked for me while the accepted answer oddly did not. Also you still need top/bottom padding to make/keep room for the thumb (which is usually larger than the bar itself) so imo this is the better answer.