How to make SeekBar take up full width of parent
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.
David Heisnam
Updated on June 20, 2022Comments
-
David Heisnam almost 2 years
I have a
SeekBar
in aRelativeLayout
whose width is equal to the screen width.I applied
layout_width="match_parent"
to theSeekBar
but it seems to keep some empty space on both sides of theSeekBar
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 customSeekBar
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 theSeekBar
class.Any help is appreciated. Thank you.
-
David Heisnam over 9 yearsI have no paddings on the parent view. But thanks for your reply.
-
David Heisnam over 9 yearsI'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 over 8 yearsit doesn't work in API 17 or above stackoverflow.com/questions/33327246/…
-
temnoi over 7 yearsas @wrkwrk mentioned, if u put
android:padding="0dp" android:paddingEnd="0dp" android:paddingStart="0dp"
everything will work perfectly -
Alon about 4 yearsHad to specify
android:paddingStart="0dp"
andandroid:paddingEnd="0dp"
for it to work -
Sahbi about 2 yearsThis 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.