【问题标题】:Setting android rating bar to nearest half stars from float variable将android评级栏设置为浮动变量中最接近的半星
【发布时间】:2013-07-09 22:26:47
【问题描述】:

我已经四处寻找解决方案,但只能找到将其设置为实际数字而不是变量的答案。

我希望评分栏显示与在 0.5 秒内上升 5 分相同的星数,因此有可能获得 3.5 等。我可以为评分栏设置单独的浮点值,但是不能对同一事物使用变量,它只是将其四舍五入到最接近的整数。

我使用的代码如下:

    RatingBar bar=(RatingBar)findViewById(R.id.ratingBar1); 
    bar.setNumStars(5);
    bar.setStepSize(0.5f);
    Bundle b = getIntent().getExtras();
    int score= b.getInt("score");
    //change the score out of ten to star rating out of 5
            float scores = score / 2;
    //display star rating
    bar.setRating(scores);

我们会收到任何帮助。谢谢。

【问题讨论】:

    标签: java android variables ratingbar


    【解决方案1】:

    分数需要设置为浮点数,而不是整数。作为一个 int 它是四舍五入的,所以你唯一需要改变的是 float score = b.getInt("score")l

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2019-05-31
      • 2016-02-17
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多