Small Style Custom rating bar (readonly custom rating bar)
Asked Answered
F

1

3

I tried to create a custom rating bar. I don't use style because I only use this once. So, I created a layer-list in the drawable folder (its name is custom_rating_bar.xml):

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
  <item
    android:id="@android:id/background"
    android:drawable="@drawable/custom_icon_empty"/>
  <item
    android:id="@android:id/secondaryProgress"
    android:drawable="@drawable/custom_icon_empty"/>
  <item
    android:id="@android:id/progress"
    android:drawable="@drawable/custom_icon"/>
</layer-list>

And I use this code in the rating bar to use those icons:

android:progressDrawable="@drawable/custom_rating_bar"

My image size is standard (48x48 for mdpi, etc) and i use a small style rating bar :

style="?android:attr/ratingBarStyleSmall"

The problem is, i cant use style="?android:attr/ratingBarStyleSmall" together with android:progressDrawable (When i did this, the images will not shown). When i delete the style (style="?android:attr/ratingBarStyleSmall") my rating bar become too big (the images are shown).

This image show how big is it (i think the margin between image is also too much) : enter image description here

So, how to make my custom rating bar smaller? (as small as the default small style rating bar).

And this custom rating bar is for show only (cant be changed by user).

Thanks.

Folder answered 10/1, 2013 at 4:59 Comment(1)
If you want this rating bar for show only, set this: android:isIndicator="true"Stereoscopy
S
3

First off, remove the "+"s from your android:id. Also, you may want to add a style in your xml, such as style="?android:attr/progressBarStyleHorizontal" depending on your needs. You might also need to use android:indeterminateDrawable="@drawable/custom_rating_bar" instead of progressDrawable

Sunglasses answered 10/1, 2013 at 5:3 Comment(11)
Thanks :D, sorry i dont know what is the relation of progressBar and rating bar?:DFolder
@BlazeTama, oh yeah I was confused too. Didn't catch that this was a rating bar. Is that what you want or you want a progress bar? the progressDrawable attribute in a ratingbar is undefined...Sunglasses
@BlazeTama actually I see they do have progressDrawablesSunglasses
I want to make a small custom rating bar. How to define it? Thanks :DFolder
@BlazeTama, lets solve one problem at a time. Did removing the "+"s fix anything?Sunglasses
Also, you're gonna have to set the min and max height on your ratingbar to match the size of the asset. otherwise, things wont look right.Sunglasses
The images shown when i remove the small style (style="?android:attr/ratingBarStyleSmall") and the '+'.But the rating bar become to big (i want the small one, as small as the small style). Do you have any idea how to do this? Thanks :DFolder
let us continue this discussion in chatFolder
If the ratingbar is just for show, why not just use an imageview with something that looks like a rating bar created by you as an asset?Sunglasses
I cant do that, because even the user cant interact with the rating bar, i still need to change the value of it :DFolder
As far as I know you can't make the ratingbar smaller in code. You need to create smaller images for the rating bar. Last time when I created a custom rating bar, this was the only way to go for me.Soni

© 2022 - 2024 — McMap. All rights reserved.