user1767260
user1767260

Reputation: 1561

Android - Set seekbar progress always left to the thumb

IF the progress is near the borders the progress line will be ahead or behind the thumb if padding and thumboffset is set for seekbar(See image):

enter image description here

    <SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true" 
    android:thumbOffset="0dp"
    android:thumb="@drawable/meterknob"
    android:paddingLeft="25dp"
    android:paddingRight="25dp"
    android:background="@android:color/darker_gray"
        />

I want seekbar always like this!

enter image description here

How can I implement this. Please help me Thanks in advance

EDIT When I applied Karthika's code . I got like below image. The problem here is it is not touching its background image's borders. I have to start it from the starting of background image.

enter image description here

Upvotes: 1

Views: 1138

Answers (1)

Karthika PB
Karthika PB

Reputation: 1373

set

   <SeekBar
            android:id="@+id/progressplay"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"

                     android:visibility="gone"
                android:background="@drawable/violetborderbox"
             android:thumb="@drawable/playbtn"
             android:progressDrawable="@drawable/seekbar_progress"

            android:layout_centerVertical="true"
             android:paddingLeft="35dp"

android:layout_centerHorizontal="true"
             android:paddingRight="35dp"/>

inside your seeekbar

and the drawable file is

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@android:id/background"
        android:drawable="@color/violetbg"
        android:dither="true">
    </item>
    <item android:id="@android:id/secondaryProgress">
        <clip>
            <shape>
                <gradient
                    android:startColor="#80028ac8"
                    android:centerColor="#80127fb1"
                    android:centerY="0.75"
                    android:endColor="#a004638f"
                    android:angle="270"
                />
            </shape>
        </clip>
    </item>
    <item
        android:id="@android:id/progress"
        android:drawable="@drawable/seekbar_progress_bg"
    />
</layer-list>

my result was

enter image description here

Upvotes: 2

Related Questions