<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(eg: 3.1).
StepSize is also set to 0.1.
Please anyone help me in this.
Thanks in Advance.
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();
}
}
});
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
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 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.