25

I ran into some weird problem..I implemented a seekbar with custom thumb..and when I ran my app on HTC Desire, it all works fine..but, when I ran it on Samsung Galaxy, the thumb becomes clipped!

Here are the screenshots..

Desire:

Desire seekbar

Samsung Galaxy:

Galaxy seekbar

I would be grateful for any thoughts..tnx

myprogress.xml:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@android:id/background">
    <shape>
        <corners
            android:radius="10dp" />
        <gradient
                android:startColor="@color/gray"
                android:centerColor="@color/gray"
                android:centerY="0.75"
                android:endColor="@color/gray"
                android:angle="270"
        />
    </shape>
</item>

<item android:id="@android:id/secondaryProgress">
    <clip>
        <shape>
        <corners
            android:radius="10dp" />
            <gradient
                    android:startColor="@color/white"
                    android:centerColor="@color/white"
                    android:centerY="0.75"
                    android:endColor="@color/white"
                    android:angle="270"
            />
        </shape>
    </clip>
</item>

<item android:id="@android:id/progress">
    <clip>
        <shape>
        <corners
            android:radius="10dp" />
            <gradient
                android:startColor="#FFA500"
                android:centerColor="@color/yellow"
                android:centerY="0.75"
                android:endColor="@color/yellow"
                android:angle="270"
            />
        </shape>
    </clip>
</item>

style:

<style name="mySeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:progressDrawable">@drawable/myprogress</item>
    <item name="android:indeterminateDrawable">@android:drawable/progress_horizontal</item>
    <item name="android:minHeight">10dip</item>
    <item name="android:maxHeight">10dip</item>
    <item name="android:thumb">@drawable/thumb</item>
    <item name="android:thumbOffset">4dp</item>
    <item name="android:focusable">true</item>

seekbar xml:

<SeekBar android:id="@+id/player_seek_horizontal"
        android:layout_gravity="center_vertical" 
        android:max="100" 
        android:layout_marginLeft="50dp" 
        android:layout_width="180dp" 
        android:thumb="@drawable/thumb" 
        android:layout_height="wrap_content" 
        style="@style/mySeekBar" 
        android:background="@drawable/background_transparent_rounded" 
        android:paddingRight="4dp" android:paddingLeft="4dp"/>
artless noise
  • 21,212
  • 6
  • 68
  • 105
Tomislav Novoselec
  • 4,570
  • 2
  • 27
  • 22
  • Please post relevant XML and source files. – sparkymat Jun 27 '11 at 10:04
  • Were you able to resolve this? I am facing the same problem with the default seekbar. Using the `padding` and `thumbOffset` makes it behave differently on different API versions. – faizal Jul 27 '14 at 05:53

3 Answers3

37

Adjust the android:paddingLeft, android:paddingRight and android:thumbOffset properties of your SeekBar to achieve desired results.

Padding right and left should be half of thumb's width.

Ragunath Jawahar
  • 19,513
  • 22
  • 110
  • 155
12
<SeekBar
    ...
    android:paddingLeft="5dp"  
    android:paddingRight="5dp"
    android:thumbOffset="0px" />

It worked for me.

Andrew
  • 36,676
  • 11
  • 141
  • 113
sandy
  • 3,311
  • 4
  • 36
  • 47
6

add following attributes to your parent layout

android:clipChildren="false"
android:clipToPadding="false"
DroidBender
  • 7,762
  • 4
  • 28
  • 37
  • 4
    It's OK bro, you're only 7 years late :) – Tomislav Novoselec Apr 19 '18 at 16:53
  • Great solution. Only needed the clipChildren part in my case. The slight drawback is the thumb will not respond if it is touched on the outer side of the seekBar layout (outer thumb half). This is a minor issue and this approach worked better than the many other options I tried for my situation. – Ben Mar 15 '21 at 02:04