Custom horizontal progressbar
Hey, I just wrote a horizontal progress bar. The progressbar gets this background resource:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
开发者_JAVA技巧 <inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_bg" />
</item>
<item android:id="@android:id/progress" android:gravity="center">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
This works fine, but the white progress has the same height as the background. But I want the progress to be smaller than the background of the progress bar, since thre background has a boarder that should not overlap.
Any ideas? Thanks
There is also :
<item android:id="@android:id/secondaryProgress"></item>
Did you changed it too?
http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList
You can try adding android:top
, android:left
,android:right
, and android:bottom
to the white progress bar item
in order to add padding to the bar.
<item android:id="@android:id/progress" android:gravity="center"
android:top="2dp" android:left="2dp" android:right="2dp" android:bottom="2dp">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
Hi actually I did not use it.
The full xml is:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_bg" />
</item>
<item android:id="@android:id/secondaryProgress" android:gravity="center">
<clip>
<shape>
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
Cheers
hi try adding stroke that has no color (opacity is max) I tried this code with my gradient progress bar:
<?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:angle="270"
android:centerColor="#f8d79b"
android:centerY="0.5"
android:endColor="#f8d79b"
android:startColor="#f8d79b" />
</shape>
</item>
<item android:id="@android:id/progress">
<clip>
<shape>
<stroke
android:width="5px"
android:color="#00ffffff" />
<corners android:radius="10dip" />
<gradient
android:angle="0"
android:endColor="#ffac17"
android:startColor="#ffac17" />
</shape>
</clip>
</item>
</layer-list>
so your code should be like this:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/progress_bg" />
</item>
<item android:id="@android:id/secondaryProgress" android:gravity="center">
<clip>
<shape>
<stroke
android:width="5px"
android:color="#00ffffff" />
<corners android:radius="5dip" />
<solid android:color="#FFF" />
</shape>
</clip>
</item>
worked for me, hope it works for you :D
精彩评论