Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

seekbar thumb center not at the start point

enter image description here

as my pic,the seekbar progress =0,but the seekbar thumb center not at the start point.my code:

   <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 image

like image 237
pengwang Avatar asked Sep 25 '13 03:09

pengwang


1 Answers

finally found the answer, the case here is that android:thumbOffset is NOT a setter for the thumb place along with the progress bar, but, it's the thumb length from it's beginning to it's center point so that the seekbar can adjust the thumb's center point at it's beginning point. So, if we have a thumb image with a width of 50, the thumbOffset has to be 25 (50/2), so that the seekbar will adjust the zero value at the pixel 25 of the thumb which will make the thumb appears to be exactly at the middle. thanks for that man who redirect me to know that.

like image 98
Muhammed Refaat Avatar answered Sep 28 '22 04:09

Muhammed Refaat