MaterialRatingBar icon indicating copy to clipboard operation
MaterialRatingBar copied to clipboard

Stars not reflecting user input

Open samcackett opened this issue 6 years ago • 7 comments

I think this is a general issue with the RatingBar for Android, but wanted to post here to be sure as I couldn't find a definitive answer.

We have the MaterialRatingBar in our app (love it btw), using width=match_parent.

On some devices, when the user taps 1 star, the 2nd star updates. If they tap the 2nd star, the 3rd updates etc. User can never select 1 star and the star they select is never the correct one.

Samsung devices seem to suffer the worst with this issue. It works fine as well on plenty of devices. If we get rid of match_parent, it seems to work on all devices too.

samcackett avatar Nov 17 '17 10:11 samcackett

Yes it might be that Samsung modified the framework RatingBar implementation and violated some contract. Since I don't have any Samsung device at hand, so I'd suggest that you try debugging the ClipDrawable.setLevel() and see if the framework RatingBar is passing the correct value, or if not so how is it different from desired value. I'd also check if this is a display issue with the drawable, or it is also wrong in RatingBar.getRating().

zhanghai avatar Nov 17 '17 19:11 zhanghai

Thank you for getting back to me so quickly, I will take a look at this next week. Have a great weekend

samcackett avatar Nov 18 '17 18:11 samcackett

This bug seems to be a result of RatingBar extending ProgressBar. It can be fixed by setting your stepSize to 0.01 and implementing custom RatingBar.OnRatingBarChangeListener.

ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
    @Override
    public void onRatingChanged(final RatingBar ratingBar, final float rating, final boolean fromUser) {
        if (fromUser) {
            ratingBar.setRating(Math.ceil(rating));
        }
    }
});

For more details, please follow the link below: https://stackoverflow.com/a/35531397

sismetanin avatar Dec 07 '17 21:12 sismetanin

@sam9046 I wonder if you had fixed this bug? (Although the fix @sismetanin mentioned is about wrap_content width and all devices)

zhanghai avatar Dec 07 '17 21:12 zhanghai

I confirm that sistematin's workaround does work. And this happened to me on xhdpi emulators of different sizes, so definitely not Samsung-specific.

leoacevedo avatar Apr 09 '18 02:04 leoacevedo

@leoacevedo Is it specific to layout_width="match_parent"? Can you reproduce it with sample app on xhdpi emulators?

zhanghai avatar Apr 09 '18 08:04 zhanghai

It's only reproduced on API level 24 (Android 7.0), I've checked on several devices with that version.

jaildigger avatar Jun 19 '18 12:06 jaildigger