hi I want to make Custom Seek Bar which look like this

and this shape what appear on Android Studio
but when it run on Phone it look like this

and here is My code
in XML
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<SeekBar
android:id="@+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:max="10000"
android:progress="500"
android:progressDrawable="@drawable/custom_seekbar"
android:thumb="@drawable/thumb_transperent"
/>
</LinearLayout>
where @drawable/custom_seekbar
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
<rotate>
<layer-list>
<item android:drawable="@drawable/progress_bar"/>
</layer-list>
</rotate>
</item>
<!-- Define the progress properties like start color, end color etc -->
<item android:id="@android:id/progress">
<clip>
<layer-list>
<item android:drawable="@drawable/progressbar_progress"/>
</layer-list>
</clip>
</item>
</layer-list>
and @drawable/progress_bar
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:top="15dp">
<shape android:shape="line">
<stroke android:color="@color/black"
android:width="5dp"/>
<solid android:color="@android:color/transparent" />
</shape>
</item>
<item
android:bottom="25dp"
android:left="0dp"
android:right="100dp"
android:gravity="left"
android:drawable="@drawable/test_small">
</item>
<item
android:left="50dp"
android:right="50dp"
android:bottom="25dp"
android:gravity="center"
android:drawable="@drawable/test_meduim">
</item>
<item
android:left="100dp"
android:bottom="25dp"
android:gravity="right"
android:drawable="@drawable/test_large">
</item>
</layer-list>
and progressbar_progress
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:top="15dp">
<shape android:shape="line">
<solid android:color="@android:color/transparent" />
<stroke android:color="@color/red" android:width="3dp"/>
</shape>
</item>
<item
android:bottom="25dp"
android:gravity="left"
android:width="19dp"
android:height="19dp"
android:drawable="@drawable/test_small">
</item>
<item
android:gravity="center"
android:right="12dp"
android:bottom="25dp"
android:width="19dp"
android:height="19dp"
android:drawable="@drawable/test_meduim">
</item>
<item
android:bottom="25dp"
android:gravity="right"
android:width="19dp"
android:height="19dp"
android:drawable="@drawable/test_large">
</item>
</layer-list>
can Any one fix this or tell me what`s wrong cuase I have tried Alot of thing and didnt work and thnak you
The images are scaled (the width and height attributes were added in API 23). To avoid this you can include a <bitmap/> element.
e.g. replace :
<item
android:width="19dp"
android:height="19dp"
android:bottom="25dp"
android:drawable="@drawable/test_small"
android:gravity="left">
</item>
with :
<item
android:bottom="25dp">
<bitmap
android:gravity="left"
android:src="@drawable/test_small" />
</item>
Notice that the gravity attribute is on the bitmap element.
The trick is explained here :
All drawable items are scaled to fit the size of the containing View, by default. Thus, placing your images in a layer list at different positions might increase the size of the View and some images scale as appropriate. To avoid scaling items in the list, use a
<bitmap>element inside the element to specify the drawable and define the gravity to something that does not scale, such as "center".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With