评分栏仅显示半颗星而不是全星

发布于 2024-12-24 16:39:21 字数 501 浏览 3 评论 0原文

我正在开发一个应用程序,需要动态创建一个 4 星的不可编辑的小样式评级栏。

当我调用 setRating(4) 时,它显示 4 颗星,没有任何问题。 但是当我调用 setRating(3) 时,它显示 3 颗半星。 setRating(2) 正确显示 2 颗星, 但 setating(1) 显示 1 颗半星。

当我在另一个活动中使用普通评级栏时,它工作正常,但是当我使用小型不可编辑评级栏时,它无法正常工作。

这与 api 级别或小样式不可编辑评级栏有什么关系吗?

初始化是这样完成的:

RatingBar ioRatingBar = new RatingBar(this,null,android.R.attr.ratingBarStyleSmall);
ioRatingBar.setNumStars(4);

ioRatingBar.setRating(3);

I'm working on an app that needs to create a non editable small style rating bar with 4 stars dynamically.

When I call setRating(4) it shows 4 stars without any problem.
But when I call setRating(3) it shows 3 and half stars.
setRating(2) shows 2 stars correctly,
but setrating(1) shows 1 and half stars.

When I use a normal rating bar in another activity it works fine, but when I use the small style non editable rating bar it doesn't work properly.

Does this have anything to do with the api level or small style non editable rating bar?

Initialization is done like this:

RatingBar ioRatingBar = new RatingBar(this,null,android.R.attr.ratingBarStyleSmall);
ioRatingBar.setNumStars(4);

ioRatingBar.setRating(3);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×眷恋的温暖 2024-12-31 16:39:21

您需要设置步长 RatingBar 像这样

ratingBar.setStepSize(1.0);

,并尝试定义 最大评级为:

ratingBar.setMax(4);

You need to set the step size of the RatingBar like this

ratingBar.setStepSize(1.0);

and also try to define the max rating as:

ratingBar.setMax(4);
面犯桃花 2024-12-31 16:39:21

如果存在padding,则删除。我建议用 margin 替换。

If exist padding, remove. I suggest replace with margin.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文