From: http://www.iteye.com/topic/689272
Ratingbar is a good component for us to display scores in the system. However, we generally want to make ratingbar better decorated and use better-looking images to replace the default images of the system, the default format is as follows:
It's a good choice:
To achieve the above effect, first write a style in styles. xml:
XML Code
- <? XML version = "1.0" encoding = "UTF-8"?>
- <Resources>
- <Style name = "foodratingbar" parent = "@ Android: style/widget. ratingbar">
- <Item name = "Android: progressdrawable"> @ drawable/food_ratingbar_full </item>
- <Item name = "Android: minheight"> 48dip </item>
- <Item name = "Android: maxheight"> 48dip </item>
- </Style>
- </Resources>
Create the food_rating_bar_full.xml file in the drawable folder. The content is as follows:
XML Code
- <? 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/food_ratingbar_full_empty"/>
- <Item Android: Id = "@ + Android: ID/secondaryprogress"
- Android: drawable = "@ drawable/food_ratingbar_full_empty"/>
- <Item Android: Id = "@ + Android: ID/progress"
- Android: drawable = "@ drawable/food_ratingbar_full_filled"/>
- </Layer-List>
Food_ratingbar_full_empty indicates that the image is not selected, and food_ratingbar_full_filled indicates that the image is selected.
Put the style in ratingbar to achieve your image effect:
XML Code
- <Ratingbar Android: Id = "@ + ID/my_rating_bar"
- ...
- Style = "@ style/foodratingbar"/>