如何将 android RatingBar 上的“9/10”变为“4.5/5”?

How do I make "9/10" a "4.5/5" on an android RatingBar?

Rating bar in Android has the attributes numStars to represent the total number of stars displayed, and the attribute stepSize表示刻度的粒度。

但是,我想将 10 的评分量表映射到 5 颗星的 RatingBar,以便 9/10 在该量表上显示为 4.5/5 颗星。 android 评分栏可以这样吗?

数字 除以二,以便最终得到超过 5 的值:

在你的情况下它是 9,所以它是 9/2 = 4.5

然后,将该值传递给您的 ratingBar:

// Retrieved Json Object. float might be redundant 
//if getNumber is already of type float
float ratingValue = (float) object.getNumber()/2;

// This is used to set the rating value
myRatingBar.setRating(ratingValue); 

// This is used to show your stars
myRatingBar.setStepSize(ratingValue);