Monday 15 August 2011

android - Rating bar with custom style shows bad images -



android - Rating bar with custom style shows bad images -

i using below icons custom rating bar:

and utilize below codes:

my custom drawable:

<?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="@drawable/ic_list_item_wstar" /> <item android:id="@+android:id/secondaryprogress" android:drawable="@drawable/ic_list_item_wstar" /> <item android:id="@+android:id/progress" android:drawable="@drawable/ic_list_item_ystar" /> </layer-list>

my custom style:

<style name="yellowratingbar" parent="@android:style/widget.ratingbar"> <item name="android:progressdrawable">@drawable/ic_ratingbar_yellow</item> <item name="android:minheight">22dip</item> <item name="android:maxheight">22dip</item> </style>

my rating bar code:

<ratingbar android:id="@+id/ratingbar1" style="@style/yellowratingbar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:isindicator="false" android:rating="3.7" />

but has not result , result looks below:

edit

the size of icons 17x17pixel. set min , max size 17dp , black lines go smaller , when set 11dp black lines disappear.

why need set min , max size less icon actual size??!!

i had same issue of dragging lines when using custom star images in rating bar.

a simple solution keep padding of 1px star image

for instance, consider 2 images below;

- image1

- image2

image1 original image of 32x32px, gives dragged effect, whereas,

image2 same image having padding of 1px makes image size 36x36px , removes drag effect.

why need set min , max size less icon actual size??

that's because have placed (17x17px) images in drawable-hdpi folder , hdpi, 17px = 11.33dp.

what place images in drawable folder , setting minheightandmaxheightto17dp job. placing images in drawable folder, not right way it.

the best practice set different pixel sizes of image, in each drawable-mdpi, drawable-hdpi, drawable-xhdpi , drawable-xxhdpi folders.

hence, 17x17px image should placed in drawable-mdpi folder. (in case), corresponding image sizes placed in folders are,

drawable-mdpi - 17x17px drawable-hdpi - 25x25px drawable-xhdpi - 34x34px drawable-xxhdpi - 51x51px

and

<item name="android:minheight">17dp</item> <item name="android:maxheight">17dp</item>

for calculating image sizes in different folders, utilize dp px conversion method

android ratingbar

No comments:

Post a Comment