Android RatingBar不接受浮点值 [英] Android RatingBar doesn't accept float values

查看:182
本文介绍了Android RatingBar不接受浮点值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中有一个android评级栏,它只显示int评级。



例如:

  float ratingValue = 1.5f; 
myRatingBar.setRating(ratingValue);

和评分栏显示2个满星。我怎样才能让它显示一个半星或两个半? 解决方案

尝试使用

  float ratingValue = 1.5f; 
myRatingBar.setRating(ratingValue); //设置评分值
myRatingBar.setStepSize(ratingValue); //显示星星

public void setStepSize(float stepSize)

设置该评级栏的步长(粒度)。
参数

stepSize此评级栏的步长。例如,如果需要半星粒度,则这将是0.5。


I have an android rating bar in my app, and it only displays int ratings.

For example:

float ratingValue = 1.5f;
myRatingBar.setRating(ratingValue);

and the ratingbar displays 2 full stars. How can I make it display one and a half stars, or two and a half?

解决方案

try to use

float ratingValue = 1.5f;
myRatingBar.setRating(ratingValue); // to set rating value
myRatingBar.setStepSize(ratingValue);// to show to stars

public void setStepSize (float stepSize)

Sets the step size (granularity) of this rating bar. Parameters

stepSize The step size of this rating bar. For example, if half-star granularity is wanted, this would be 0.5.

这篇关于Android RatingBar不接受浮点值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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