How to make SeekBar tackle the full width of the parent

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

I applied layout_width="match_parent" to the SeekBar , but there seems to be some free space on both sides of the SeekBar to accommodate the thumb.

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

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

Any help is appreciated. Thanks.

+5
source share
4 answers

Try defining the following with a SeekBar in xml:

 android:padding="0dp" 
+18
source

Just solved this problem in my application. The fact is that even if you did not set the seekBar scroll, there may be some paddings (paddingLeft, paddingTop, paddingRight, paddingBottom, paddingStart, paddingEnd) in the theme that the appTheme application expands. Set these paddings to 0dp, it should work fine.

+3
source
  android:paddingStart="0dp" android:paddingEnd="0dp" 

Worked for me.

+3
source

Before you post your xml, I think your RelativeLayout has lines as shown below.

 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 that your RelativeLayout does not fill the screen, the search barrier is filled in its parent layout (RelativeLayout). Therefore, you cannot get the idea you need.

0
source

Source: https://habr.com/ru/post/1201610/


All Articles