Search code examples
javaandroidratingbar

Android RatingBar shows extra remainder


I'm using the standard Android RatingBar. It seems to behave quite weird. For some reason I can't select only full stars. It always shows a little bit more or less. Also the .setNumStars property doesn't seem to work. I'm using the following code:

RatingBar ratingbar = new RatingBar(this);
ratingbar.setLayoutParams(lp);
ratingbar.setVisibility(View.VISIBLE);
ratingbar.setNumStars(5);
ratingbar.setStepSize(1);
ratingbar.setRating(1);
linearLayoutReviews.addView(ratingbar);

When I select 1 star it selects one star:

When I select 2 stars:

enter image description here

When I select 3 stars:

enter image description here

When I select 4 stars:

enter image description here

And when I select 5 stars:

enter image description here

So for some reason it shows more than 5 stars, and there will always be a remainder of the next star selected

EDIT

When I set .setNumStars to 6 I can select them one by one, but than ofcourse, I have six

EDIT

This is the xml of the LinearLayout

<LinearLayout
                android:id="@+id/linearLayoutReviews"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="10dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginStart="10dp"
                android:orientation="vertical"
                app:layout_constraintLeft_toLeftOf="parent"
                app:layout_constraintRight_toRightOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView5"></LinearLayout>

Solution

  • I have fixed it by making a new linearlayout and placing it below the old linearlayout. I added the ratingbar to the new linearlayout