Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The Android RatingBar has "bad" threshold for certain devices, fix?

I have a standard implementation of a RatingBar. 5 stars, 1 in stepsize.

<RatingBar
    android:id="@+id/ratingBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:numStars="5"
    android:stepSize="1"
    android:progressDrawable="@drawable/dark"
    android:rating="@={viewModel.rating}"
/>

I have noticed that I have a problem on some devices, or brands actually: Samsung, Nexus, maybe more... But I don't have the issue on Sony and LG devices, maybe more here as well.

The problem is that the precision when selecting a value is really bad. It seems like if I pass the middle of the rating-drawable it will fill the following "star". It seems to be the threshold for those devices and that's just the way it is. They way the LG and Sony behaves is that when you pass half the distance between two "stars", then it fills in the next star.

So, is there anything I can do to prevent this?

like image 627
Yokich Avatar asked Sep 13 '16 12:09

Yokich


1 Answers

As far as I know, there is no way around it.

I'm the creator of a library which provides an alternative to Android's default RatingBar: SimpleRatingBar, and we discussed this behaviour in one issue.

In the library, we modified this behaviour so one star will be selected only if at least 1/4 of it is pressed. I believe this improves the overall experience when using it.

If you want to, you can give it a try. It features:

  • Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
  • Arbitrary number of stars.
  • Arbitrary step size.
  • Size of stars can be controlled exactly or by setting a maximum size.
  • Customizable colors in normal state (border, fill and background of stars and rating bar).
  • Customizable colors in pressed state (border, fill and background of stars and rating bar).
  • Customizable size separation between stars.
  • Customizable border width of stars.
  • Customizable stars corner radius.
  • Allows to set OnRatingBarChangeListener
  • Stars fill can be set to start from left to right or from right to left (RTL language support).
  • AnimationBuilder integrated in the view to set rating programatically with animation.

Here is a preview of it

You can find it either in jcenter or in Maven Central. So in your build.gradle file just add to your dependencies:

compile 'com.iarcuschin:simpleratingbar:0.1.+'

I hope it's useful.

like image 107
FlyingPumba Avatar answered Oct 03 '22 04:10

FlyingPumba