0

I don't understand why Android's RatingBar widget doesn't scale to the width I specify in the layout.

If I have something simple like

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".home.view.TempActivity">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="170dp"
        android:layout_height="220dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.AppCompatRatingBar
            android:id="@+id/ratingBar"
            style="?attr/ratingBarStyleIndicator"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:isIndicator="true"
            android:max="5"
            android:numStars="5" />
    </androidx.cardview.widget.CardView>

</androidx.constraintlayout.widget.ConstraintLayout>

The last star is cut off. Sure, I could use ratingBarStyleSmall instead of ratingBarStyleIndicator, but then it's too small. How can you get it so it simply scales to the width of the parent (in this case, a CardView at 170dp)?

user1795832
  • 2,080
  • 8
  • 29
  • 50

2 Answers2

0

You can change the card width as wrap content.

Hanish
  • 47
  • 7
0

you should set card view android:layout_width to wrap_content.

and to resize RatingBar you can do this:

     <androidx.appcompat.widget.AppCompatRatingBar
        android:id="@+id/ratingBar"
        style="?attr/ratingBarStyleIndicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:isIndicator="true"
        android:max="5"
        android:numStars="5"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp"
        android:scaleY="0.8"
        android:scaleX="0.8" />

How can I decrease the size of Ratingbar?

Ehsan msz
  • 1,774
  • 2
  • 13
  • 26