-1

I need to make precise rating bar with 5 stars, but when i have something like 2.7 rating i need to have 2.7 stars in white the others in grey. I was thinking something with the seeker bar. I added 5 stars and can easily make 4 grey when I have rating 1, but not sure how to make them partially colored.

enter image description here

I have something like this now :

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            setStars(i);
        }

 private void setStars(int stars){
    switch (stars){
        case 0:
            star1.setVisibility(GONE);
            star2.setVisibility(GONE);
            star3.setVisibility(GONE);
            star4.setVisibility(GONE);
            star5.setVisibility(GONE);
            break;
case 2:
            star1.setVisibility(VISIBLE);
            star2.setVisibility(GONE);
            star3.setVisibility(GONE);
            star4.setVisibility(GONE);
            star5.setVisibility(GONE);
            break;

And so on but I need it to be precise. I know i can probably make 10 states of the star for 1/10, 2/10 filled etc but that will be too much work.

STARGATEBG
  • 251
  • 1
  • 8

2 Answers2

3

To reduce size and change stepSize you can do something like this

<RatingBar
android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:stepSize="0.1"
style = "?android:attr/ratingBarStyleSmall"/>

And to style your rating bar you can see this link Styling Rating Bar

Community
  • 1
  • 1
Vivek Mishra
  • 5,669
  • 9
  • 46
  • 84
2

Try this:

<RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:numStars="5"
        android:stepSize="0.1"
        android:rating="2.7" />
Suhas Bachewar
  • 1,230
  • 7
  • 21
  • Hey thanks ... I had no idea there is stepSize. Now the only thing left is can I make them smaller and use custom drawables and colors? – STARGATEBG Aug 24 '16 at 09:36