android set part of the stars in the rating bar if the value is in decimal places

拜拜、爱过 提交于 2019-12-03 15:52:56

You can find it here:

    float d= (float) ((number*5) /100);
    RatingBar rb = (RatingBar) findViewById(R.id.ratingBar1);
    rb.setRating(d);

And on your layout:

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:isIndicator="true"
    android:max="5"
    android:stepSize="0.01" />
yadu007

If you want to show rating in exact points you need to set stepSize in

rate.setStepSize((float) 0.1);
rate.setRating((float)3.6);

It will show Fourth star be filled more than half.

Via XML

<RatingBar
 .....
 android:max="5"
 android:numStars="5"
 android:progressTint="@color/golden"
 android:rating="2"
 android:stepSize="1"/>

Via Java Code

  ratingBar.setMax(5);
  ratingBar.setNumStars(5);
  ratingBar.setStepSize(0.1f);

Wait.. there's more

You'll have to set width attribute of your RatingBar to wrap_content otherwise the above mentioned attributes won't have an effect on the UI.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!