Seekbar and InsetDrawable for progress
Hi I try to customize a seekbar.
Here's my Problem:
main.xml
...
<SeekBar android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:thumb="@drawable/seekbarthumb"
android:progressDrawable="@drawable/sb2"
android:minHeight="45dip"
android:maxHeight="45dip"
></SeekBar>
...
sb2.xml in @drawable
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress"
android:drawable="@drawable/sb_progress">
</item>
</layer-list>
Everything works fine, but the sb_progress was on the wrong position.
So i have 2 solutions. Change the position of the sb_progress or edit sb_progress with Photoshop and add transparent pixels to fix it.
By trying the good way of changing the position something went wrong:
i added some lines to the sb2.xml
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"
android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress" >
<inset
android:drawable="@drawable/sb_progress"
android:insetTop="11dip"开发者_如何转开发
android:insetBottom="11dip"
android:insetLeft="11dip">
</inset>
</item>
</layer-list>
I added the inset element, but the result suxx. the position is correct but the progress isn't animating anymore. The sb_progress.png is always full drawn and don't stop at the thumb.
I need help! Is this a Bug and I need to add transparent Pixels? Isn't
InsetDrawable a subclass of Drawable. Why the seekbar doesn't work anymore with an InsetDrawable.
java.lang.Object ↳ android.graphics.drawable.Drawable ↳ android.graphics.drawable.InsetDrawable
I know this is an old question, but if anyone finds this through a search engine (like I did) all you need to do is add a 'clip' to the drawable as well as an inset.
<item android:id="@android:id/progress" >
<clip>
<inset
android:insetRight="11dp"
android:insetLeft="11dp">
<shape>
<solid android:color="#343434"/>
</shape>
</inset>
</clip>
</item>
精彩评论