How can I decrease the size of Ratingbar?

2019-03-08 12:29发布

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 it with the following style:

<RatingBar
style = "?android:attr/ratingBarStyleSmall"
android:numStars = "5"
android:rating   = "4" />

Now, the size is reduced but number of stars and rating do not take effect!!! Why? I have 7 stars that 6 of them is selected.

13条回答
Root(大扎)
2楼-- · 2019-03-08 12:42

This was my solution after a lot of struggling to reduce the rating bar in small size without even ugly padding

 <RatingBar
        android:id="@+id/listitemrating"
        style="@android:attr/ratingBarStyleSmall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleX=".5"
        android:scaleY=".5"
        android:transformPivotX="0dp"
        android:transformPivotY="0dp"
        android:isIndicator="true"
        android:max="5" />
查看更多
Explosion°爆炸
3楼-- · 2019-03-08 12:47
<RatingBar
  style="?android:attr/ratingBarStyleIndicator"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
/>
查看更多
淡お忘
4楼-- · 2019-03-08 12:50

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"
查看更多
贪生不怕死
5楼-- · 2019-03-08 12:52

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.

查看更多
Fickle 薄情
6楼-- · 2019-03-08 12:54

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" />
查看更多
放我归山
7楼-- · 2019-03-08 12:56

Using Widget.AppCompat.RatingBar, you have 2 styles to use; Indicator and Small for large and small sizes respectively. See example below.

<RatingBar
    android:id="@+id/rating_star_value"
    style="@style/Widget.AppCompat.RatingBar.Small"
    ... />
查看更多
登录 后发表回答