当我为Android RatingBar使用自定义星标时,对于低于0.5的十进制值始终显示半星 [英] When I use custom stars for Android RatingBar, always show half star for decimal values below 0.5

查看:399
本文介绍了当我为Android RatingBar使用自定义星标时,对于低于0.5的十进制值始终显示半星的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我查看了许多帖子(例如 Android RatingBar更改星形颜色更改在Android中动态创建评级栏的评级栏中的星星的颜色如何设置分级栏的星形?),以便更改分级栏中的星形颜色。我关注了帖子并能够更改自定义RatingBar的星号,但是这样做后,我无法再将值设置为小于一半的小数(例如0.2)。它总是显示为一半(例如0.5)。当我将该值设置为一半以上(例如0.7)时,它会完美显示。

I've looked up a number of posts (e.g. Android RatingBar change star colors, Change the color of the stars in the rating bar where the rating bar is created dynamically in android, How can I set the star color of the ratingbar?) in order to change the colours of the stars in the RatingBar. I followed the posts and was able to change the stars for the custom RatingBar, but in doing this I was no longer able to set the value to be a decimal lower than a half (e.g. 0.2). It would always show up as the half (e.g. 0.5). When I set the value to be above the half (e.g. 0.7) it displays perfectly.

以下是我用于自定义RatingBar的示例图像(即ratingbar_empty .png,ratingbar_half.png,ratingbar_full.png)

The following are the sample images that I am using for my custom RatingBar (i.e. ratingbar_empty.png, ratingbar_half.png, ratingbar_full.png)



以下是使用自定义星标的xml(ratingbar_custom.xml)。 / p>

The following is the xml to use the custom stars (ratingbar_custom.xml).

<?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/ratingbar_empty" />
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/ratingbar_half" />
    <item android:id="@android:id/progress" android:drawable="@drawable/ratingbar_full" />
</layer-list>'

然后我将如何使用自定义

The following is then how I use my custom RatingBar in my layout.

<RatingBar 
    android:id="@+id/rb_rating"
    android:numStars="7"
    android:rating="0"      
    android:stepSize="0.01"                     
    android:isIndicator="true"                                                            
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:progressDrawable="@drawable/ratingbar_custom" />

当我将它们放在一起并将RatingBar的值设置为0.2时,它将设置RatingBar可视化为0.5,如下所示。有谁知道为什么会这样或我在做什么错?任何帮助将不胜感激。谢谢

When I then put it all together and set the value of the RatingBar to be 0.2, it sets the RatingBar visually to 0.5, as shown below. Has anyone any ideas why this is happening or what I'm doing wrong? Any help would be greatly appreciated. Thanks

推荐答案

您不需要star_half。

You don't need star_half.

尝试为此:

<?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/star_none" />
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/star_none" />
    <item android:id="@android:id/progress" android:drawable="@drawable/star_fill" />
</layer-list>

这篇关于当我为Android RatingBar使用自定义星标时,对于低于0.5的十进制值始终显示半星的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆