The center of the thumb is not at the starting point

enter image description here

like my pic, progress in the search bar = 0, but the center of the search thumb is not at the starting point. My code is:

<SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:progressDrawable="@drawable/seekbar_progress" android:thumb="@drawable/seekbarthumb" android:minHeight="10dip" android:maxHeight="10dip" android:thumbOffset="0px" android:max="100" android:id="@+id/bright_seekbar" android:layout_marginLeft="60dip"/> 

seekbar_progress

  <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@android:id/background"> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#ff9d9e9d" android:centerColor="#ff5a5d5a" android:centerY="0.75" android:endColor="#ff747674" android:angle="270" /> </shape> </item> <item android:id="@android:id/secondaryProgress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#80ffd300" android:centerColor="#80ffb600" android:centerY="0.75" android:endColor="#a0ffcb00" android:angle="270" /> </shape> </clip> </item> <item android:id="@android:id/progress"> <clip> <shape> <corners android:radius="5dip" /> <gradient android:startColor="#FFD700" android:centerColor="#FFB90F" android:centerY="0.75" android:endColor="#FFA500" android:angle="270" /> </shape> </clip> </item> </layer-list> 

seekbarthumb.xml

 <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true" android:drawable="@drawable/pressed_button__volume" /> <item android:state_focused="true" android:drawable="@drawable/pressed_button__volume" /> <item android:drawable="@drawable/default_button__volume" /> </selector> 

default_button__volume is an image

+5
android seekbar
source share
6 answers

finally found the answer, here the fact is that android:thumbOffset is NOT a thumb installer along with a progress bar , but this is the length of the thumb from , starting from to , so that the seekbar center can adjust the center point of the thumb at the starting point. So, if we have a thumb image with a width of 50 , thumbOffset should be 25 (50/2), so the seekbar adjust > zero at pixel 25 of the thumb, which causes the thumb to be exactly in the middle. thanks to this person who redirects me to this.

+9
source share

Your thumb image should have a yellow dot in the center (horizontal); add transparent pixels left or right to do so. Then change android:thumbOffset to half the size of your thumb. For example, if your image is 10dp wide, set android:thumbOffset to 5dp .

+3
source share

For me, the solution is to add the value of android:thumbOffset as appropriate for your layout, and not set it as half the width of the thumb icon. If you set android:thumbOffset as a + ve value (e.g. 10dp), your thumb moves to the left side and this value is -ve (e.g. -10dp) than your thumb moves to the right side .

+1
source share

try giving thumbOffset a negative value in the search bar (e.g. -3px).

0
source share

Add

 android:progress="0" 

for seekbar in xml file.

OR

in Java file:

 SeekBar sb = (SeekBar) v.findViewById(R.id.bright_seekbar); sb.setMax(100); sb.setProgress(0); // Set it to zero so it will start at the left-most edge 

This should solve your problem.

0
source share

Set thumbOffset of your search bar to double the width of your thumb. If your thumb width is 8dp, then set android: thumbOffset to 16dp. This worked in my case.

0
source share

All Articles