'Progress bar does not fit the background drawable
I'm working on a horizontal progress bar and the progress does not seem to be fitting the drawable image. It starts after like 5dp.
This is my code.
<SeekBar
style="?android:attr/progressBarStyleHorizontal"
android:id="@+id/progress_bar"
android:layout_width="1070dp"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:layout_gravity="center_vertical"
android:layout_weight="0.33"
android:background="@drawable/progress_bar"
android:max="100"
android:progressDrawable="@drawable/seekbar_style" />
My seekbar style.
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/progress">
<clip>
<shape>
<corners android:radius="4dip" />
<gradient
android:angle="270"
android:endColor="#ff0a75b0"
android:startColor="#ff0a75b0" />
</shape>
</clip>
</item>
<item android:id="@android:id/secondaryProgress">
<clip>
<shape>
<corners android:radius="4dip" />
<gradient
android:angle="270"
android:endColor="#ff0a75b0"
android:startColor="#ff0a75b0" />
</shape>
</clip>
</item>
What am I doing wrong?
Solution 1:[1]
Try this:
<SeekBar
android:id="@+id/slider"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:max="100"
android:progress="0"
android:progressDrawable="@drawable/progress_drawable" />
progress_drawable.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>
<corners android:radius="10dip" />
<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
android:clipOrientation="horizontal"
android:gravity="left">
<shape>
<corners
android:radius="5dip" />
<gradient
android:startColor="@color/greenStart"
android:centerColor="@color/greenMid"
android:centerY="0.75"
android:endColor="@color/greenEnd"
android:angle="270"
/>
</shape>
</clip>
</item>
</layer-list>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | KishuDroid |