How to Make a Smaller Ratingbar

How to make a smaller RatingBar?

The default RatingBar widget is sorta' lame.

The source makes reference to style "?android:attr/ratingBarStyleIndicator" in addition to the "?android:attr/ratingBarStyleSmall" that you're already familiar with. ratingBarStyleIndicator is slightly smaller but it's still pretty ugly and the comments note that these styles "don't support interaction".

You're probably better-off rolling your own. There's a decent-looking guide at http://kozyr.zydako.net/2010/05/23/pretty-ratingbar/ showing how to do this. (I haven't done it myself yet, but will be attempting in a day or so.)

Good luck!

p.s. Sorry, was going to post a link to the source for you to poke around in but I'm a new user and can't post more than 1 URL. If you dig your way through the source tree, it's located at frameworks/base/core/java/android/widget/RatingBar.java

How can I decrease the size of Ratingbar?

The original link I posted is now broken (there's a good reason why posting links only is not the best way to go). You have to style the RatingBar with either ratingBarStyleSmall or a custom style inheriting from Widget.Material.RatingBar.Small (assuming you're using Material Design in your app).

Option 1:

<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
... />

Option 2:

// styles.xml
<style name="customRatingBar"
parent="android:style/Widget.Material.RatingBar.Small">
... // Additional customizations
</style>

// layout.xml
<RatingBar
android:id="@+id/ratingBar"
style="@style/customRatingBar"
... />

android ratingbar small style

I once had a problem like yours whereby android seems not to consider the resizing of rating bars. All the styles I applied was not small enough to my use case. I ended up using the third party libraries.
The first one or The second one These libraries will help you resizing the rating bars. Because android parent styles of rating bars are hard to resize and do not have default implementation. Happy Coding!

How to set the colors of Android small RatingBar

Use style="?attr/ratingBarStyleSmall" style:

<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:rating="3.3"
android:theme="@style/RatingBar"
android:id="@+id/go_rating"
style="?attr/ratingBarStyleSmall"/>

see also: https://stackoverflow.com/a/3173594/5183999

Rating bar with custom size

You can try to set the parameters from styles:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomRatingBar" parent="@android:style/Widget.RatingBar" >
<item name="android:numStars">5</item>
<item name="android:stepSize">1.0</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:paddingBottom">44dp</item>
<item name="android:layout_marginLeft">4dp</item>
<item name="android:layout_marginTop">4dp</item>
</style>
<resources />

And then in your RatingBar add a style:

style="@style/CustomRatingBar"

How to do small Rating Bar in android studio?

You can use scaleX and scaleY if you want to reduce the size of the rating bar like this:

    <RatingBar
android:id="@+id/ratingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:scaleX="0.5"
android:scaleY="0.5"
/>

How to set the custom size of the stars in RatingBar

Android won't scale a rating bar icons. When you decrease the minHeight and maxHeight android will always crop the icons as shown on the picture. The workaround for it and seems to be the only one solution is to provide your own icons for stars with the desired dimensions and set the minHeight and maxHeight to the size of the icons.

RatingBar with small white stars

you can use progressTint for this purpose

  <RatingBar
android:id="@+id/vendorRatingBarValue"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignRight="@+id/reviewerName"
android:clickable="false"
android:gravity="left|center"
android:isIndicator="true"
android:numStars="5"
android:progressTint="@color/white"

android:transformPivotX="0dp"

/>


Related Topics



Leave a reply



Submit