简体   繁体   English

Android RatingBar评分设置不正确

[英]Android RatingBar rating is not set correctly

I use two RatingBars in my xml layout: 我在xml布局中使用了两个RatingBars:

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.25"
    android:rating="4.25"/>

<RatingBar
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.25"
    android:rating="4.5"/>

Even though I set ratings to 4.25 and 4.5 , both RatingBars display wrong number of stars filled. 即使我将等级设置为4.254.5 ,两个RatingBars都显示错误的满星数量。 On an Android 6 device it looks like this: 在Android 6设备上,它看起来像这样:

ratingBars

On an android 4.3 device, it looks like this: 在android 4.3设备上,它看起来像这样:

ratingBars

But on xml design view, I can see 4.25 and 4.5 are set. 但是在xml设计视图上,我可以看到设置了4.25和4.5。 Can anyone tell me why? 谁能告诉我为什么? I do not do anything with the rating bars in my code). 我对代码中的评分栏不做任何操作。

Thanks. 谢谢。

In my opinion the problem is related to android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint . 我认为问题与android:progressTint ,android:progressBackgroundTint & android:secondaryProgressTint Try to add following lines to your rating bar: 尝试将以下几行添加到您的评分栏中:

android:progressTint="Color1"
android:progressBackgroundTint="Color2"
android:secondaryProgressTint="Color3"

also try to add style to your rating bar as following: 也尝试将样式添加到评分栏,如下所示:

<style name="RatingBar" parent="Theme.AppCompat"">
<item name="colorControlNormal">@color/yourColor1</item>
<item name="colorControlActivated">@color/yourColor2</item></style>

and finally add a the following line in your rating bar 最后在评分栏中添加以下行

style="@style/RatingBar"

It will work for you. 它将为您工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM