How can I decrease the size of Ratingbar?

后端 未结 16 2179
Happy的楠姐
Happy的楠姐 2020-12-12 20:08

In my activity I have some Rating bars. But the size of this bar is so big! How can I make it smaller?

Edit

Thanks to Gabriel Negut, I did

相关标签:
16条回答
  • 2020-12-12 20:23

    You can set it in the XML code for the RatingBar, use scaleX and scaleY to adjust accordingly. "1.0" would be the normal size, and anything in the ".0" will reduce it, also anything greater than "1.0" will increase it.

    <RatingBar
      android:id="@+id/ratingBar1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:scaleX="0.5"
      android:scaleY="0.5" />
    
    0 讨论(0)
  • 2020-12-12 20:23

    If you only need the default style, make sure you have the following width/height, otherwise the numStars could get messed up:

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    
    0 讨论(0)
  • 2020-12-12 20:24

    Working Example

                 <RatingBar
                    style="@style/RatingBar"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:numStars="5"
                    android:rating="3.5"
                    android:stepSize="0.5" />
    

    and add this in your styles xml file

    <style name="RatingBar"   
    parent="android:style/Widget.Material.RatingBar.Small">
    <item name="colorControlNormal">@color/primary_light</item>
    <item name="colorControlActivated">@color/primary_dark</item>
    </style>
    

    This way you dont need to customise ratingBar.

    0 讨论(0)
  • 2020-12-12 20:24
    <RatingBar
      style="?android:attr/ratingBarStyleIndicator"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
    />
    
    0 讨论(0)
  • 2020-12-12 20:27

    Check my answer here. Best way to achieve it.

     <style name="MyRatingBar" parent="@android:style/Widget.RatingBar">
       <item name="android:minHeight">15dp</item>
       <item name="android:maxHeight">15dp</item>
       <item name="colorControlNormal">@color/white</item>
       <item name="colorControlActivated">@color/home_add</item>
    </style>
    

    and use like

    <RatingBar
        style="?android:attr/ratingBarStyleIndicator"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:isIndicator="false"
          android:max="5"
          android:rating="3"
          android:scaleX=".8"
          android:scaleY=".8"
          android:theme="@style/MyRatingBar" />
    
    0 讨论(0)
  • 2020-12-12 20:34

    This Worked for me.
    Check this image

                android:id="@+id/ratingBar"
                style="?android:attr/ratingBarStyleIndicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:numStars="5"
                android:scaleX=".8"
                android:scaleY=".8"
                android:stepSize="0.5"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0.543"
                app:layout_constraintStart_toEndOf="@+id/title"
                app:layout_constraintTop_toTopOf="parent" />
    
    0 讨论(0)
提交回复
热议问题