Question

I'm working with a default rating bar and require a stepSize of .25 - according to the docs, this should be a simple matter of setting the xml attribute android:stepSize to 0.25.

Currently, that is in place, with the total xml as:

<RatingBar 
        android:id="@+id/ratingbar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/RatingBarBig"
        android:layout_below="@+id/score"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        android:paddingBottom="5dp"
        android:layout_centerVertical="true"
        android:isIndicator="true"
        android:stepSize="0.25"
        android:numStars="5"
        android:rating="0"/>

I'm filling the ratingbar programmatically with a float of 3.25 using the following code:

float rating = 3.25f;
RatingBar mRating = (RatingBar) findViewById(R.id.ratingbar);
mRating.setRating(rating);

so, the problem is that the rating bar itself is being filled to show 3.5 instead of 3.25. I've even set Log.d notices on both the rating float and the output of mRating.getRating

Anybody have any ideas?

Était-ce utile?

La solution

Ah - so after 2 days of trying to figure this out, I finally ask SO, and what happens? I figured it out ten minutes later...

The issue was in my drawable.

What I forgot to mention, is that I'm using a second RatingBar, overlayed on top of the first one (with just empty transparent stars), as I'm using a colour filter on the primary one in order to change the colour of the stars based on the rating (red, yellow, green).

What was happening is that the drawables I was using for the primary RatingBar needed to use the exact same ones as the overlay - and not the ones I was using that were left over from my previous theme...

So, it all comes down to the images used, not the code. I'll accept this as the right answer once I'm allowed to.

Autres conseils

Try setting the step size programmatically:

mRating.setStepSize((float) 0.25);

call this before mRating.setRating(rating);

See if this works

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top