15

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.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69
David Heisnam
  • 2,463
  • 1
  • 21
  • 32

4 Answers4

28

Try to define following with the SeekBar in xml:

android:padding="0dp"
Niko
  • 8,093
  • 5
  • 49
  • 85
  • 1
    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. – David Heisnam Sep 02 '14 at 06:57
  • 6
    it doesn't work in API 17 or above http://stackoverflow.com/questions/33327246/how-to-make-android-seekbar-full-width-in-api-17-or-above –  Oct 25 '15 at 08:39
  • 3
    as @wrkwrk mentioned, if u put `android:padding="0dp" android:paddingEnd="0dp" android:paddingStart="0dp"` everything will work perfectly – vchornenyi Sep 16 '16 at 21:03
  • 2
    Had to specify `android:paddingStart="0dp"` and `android:paddingEnd="0dp"` for it to work – Alon Feb 13 '20 at 12:41
16
 android:paddingStart="0dp"
 android:paddingEnd="0dp"

Worked for me.

Shashwat
  • 525
  • 4
  • 8
  • 1
    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. – Sahbi Mar 26 '22 at 12:56
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.

wrkwrk
  • 2,261
  • 15
  • 21
0

Before you post your xml,I guess that your RelativeLayout has lines as following

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"

This means your RelativeLayout do not fill up the screen,seekbar is fill up in its parent layout(RelativeLayout).So you can not get view you want.

SeanChense
  • 846
  • 8
  • 14