2

Is there a way to change RatingBar Widget size , programmatically without using xml styles?

I know we can customize size of RatingBar using xml styles , but it is still not generic enough , i seem to encounter some of good github libraries that achieve this goal but they are offering it for cost of API 15+ , my minSDK is 10 , so can anyone help identify solution to :

Reduce size of ratingBar widget programmatically under api 10 ?

Community
  • 1
  • 1
Zulqurnain Jutt
  • 1,083
  • 3
  • 15
  • 41

1 Answers1

0

This a long shot, but:

  • If you are using only stars (no custom shapes).
  • You are willing to use API 11+.

I made a library which might help you: SimpleRatingBar.

It features:

  • Fully working android:layout_width: it can be set to wrap_content, match_parent or abritary dp.
  • Arbitrary number of stars.
  • Arbitrary step size.
  • Size of stars can be controlled exactly or by setting a maximum size.
  • Customizable colors in normal state (border, fill and background of stars and rating bar).
  • Customizable colors in pressed state (border, fill and background of stars and rating bar).
  • Customizable size separation between stars.
  • Customizable border width of stars.
  • Customizable stars corner radius.
  • Allows to set OnRatingBarChangeListener
  • Stars fill can be set to start from left to right or from right to left (RTL language support).
  • AnimationBuilder integrated in the view to set rating programatically with animation.

Here is a preview of it.

To change the width you can change it as you would do with any other view (more info). For example:

ratingBar.getLayoutParams().width = newWidth;
ratingBar.invalidate();

You can find it either in jcenter or in Maven Central. So in your build.gradle file just add to your dependencies:

compile 'com.iarcuschin:simpleratingbar:0.1.+'

I hope it's useful.

Community
  • 1
  • 1
FlyingPumba
  • 1,015
  • 2
  • 15
  • 37