#StackBounty: #android #seekbar #android-seekbar #seekbar-thumb Android custom SeekBar – progress is not following the thumb

Bounty: 50

I want to create a custom SeekBar, but I get this problem where the progress is not following the thumb of the SeekBar at certain places (around progress value from 0-10 and from 90-100). I believe it happens because I set the thumbOffset to 0, in order for the thumb to stay inside the progress bar. I want to make an iPhone style SeekBar.

SeekBar at progress 0 (is OK):

enter image description here

SeekBar at progress 5 (is NOT OK):

enter image description here

SeekBar at progress 50 (is OK):

enter image description here

SeekBar at progress 90 (is NOT OK):

enter image description here

SeekBar at progress 100 (is OK):

enter image description here

It looks like the thumbOffset is not being considered when drawing the progress based on the thumb position. I tried changing the thumbOffset to half of the width of the thumb and did all kinds of combinations with different paddings, but nothing solved the problem. I also tried all of the other solutions I found on SO.

Here’s the XML I’m using:

SeekBar definition:

<SeekBar
    android:id="@+id/scan_seekbar"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="0.5"
    android:max="100"
    android:progress="5"
    android:progressDrawable="@drawable/bg_seekbar"
    android:splitTrack="false"
    android:thumbOffset="0dp"
    android:thumb="@drawable/seekbar_thumb" />

Drawable bg_seekbar.xml:

<?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 android:shape="rectangle">
            <size android:height="48dp"/>
            <corners android:radius="25dp"/>
            <stroke android:color="@color/semiLightBlue" android:width="1dp"/>
        </shape>
    </item>

    <item android:id="@android:id/progress">
        <clip>
            <shape android:shape="rectangle">
                <corners android:radius="25dp"/>
                <size android:height="48dp"/>
                <stroke android:color="@color/colorAccent" android:width="1dp"/>
                <solid android:color="@color/colorAccent"/>
            </shape>
        </clip>
    </item>
</layer-list>

SeekBar thumb seekbar_thumb.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/colorAccent"/>
            <corners android:radius="25dp"/>

            <padding android:bottom="8dp" android:top="8dp" android:left="16dp" android:right="16dp" />
        </shape>
    </item>


    <item android:drawable="@drawable/ic_swipe_white" android:gravity="center" android:height="32dp" android:width="44dp"/>
</layer-list>

Did anyone else face this problem?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.