0
   <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="0.1"
    android:isIndicator="true"
    android:rating="3.1"
    />

If I give rating from 3.1 to 3.5,then rating showing is 3.5 only.

I need rating to be set in exact value(e.g: 3.1).

StepSize is also set to 0.1.

Please anyone help me in this.

Thanks in Advance.

Akila
  • 715
  • 2
  • 8
  • 13

3 Answers3

0

TRY LIKE THIS

  <RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1"
    />


    ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
        @Override
        public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {

            if(rating == 1.0)
            {
                Toast.makeText(MainActivity.this, "3.1", Toast.LENGTH_SHORT).show();
            }
            else if(rating == 2.0)
            {
                Toast.makeText(MainActivity.this, "3.2", Toast.LENGTH_SHORT).show();
            }

        }
    });
Ricky Patel
  • 465
  • 2
  • 12
0

Try this:

<android.support.v7.widget.AppCompatRatingBar
            android:id="@+id/rb"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            android:isIndicator="false"
            android:numStars="6"
            android:stepSize=".1"
            app:secondaryProgressTint="#00000000"
            android:numStars="6"
           />

If you set secondaryProgressTint in RatingBar, it will work with versions >= 21. To support all versions use AppCompatRatingBar

Faraz
  • 2,144
  • 1
  • 18
  • 28
-1

Try to adjust your ratingBar with the property android:width="match_parent" in your parent layout, this will take your step size in mind and behave with decimal rating.

you can better get it Here.