Reputation: 3173
I am displaying rating bar in my application where i want to reduce the dimensions of the star. so here is xml of rating bar
<RatingBar
android:id="@+id/ratingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:max="5"
android:stepSize="0.25"
android:numStars="0"
android:focusable="false"
android:layout_gravity="center_horizontal"
android:focusableInTouchMode="false"
android:isIndicator="true"/>
i am setting color and setting rating like this
private RatingBar ratingBar;
Drawable ratingBarColor = ratingBar.getProgressDrawable();
ratingBar = (RatingBar) view.findViewById(R.id.ratingBar);
Drawable ratingBarColor = ratingBar.getProgressDrawable();
ratingBar.setRating((float) (value));
DrawableCompat.setTint(ratingBarColor, ContextCompat.getColor(getActivity(), R.color.red));
But the problem is regardless of any value the color and decimal filling won't work.I am using style to reduce star dimensions.strange is if i remove style attribute in xml it will set exact value as star but dimension will reset to default.if i add min/max height to star the image will get cropped.
here is the same problem :- How to set the custom size of the stars in RatingBar
tried :style="?android:attr/ratingBarStyleIndicator"
still same issue.
i am not getting what's wrong with the style attribute.
Upvotes: 1
Views: 1740
Reputation: 1053
I don't know if it will be useful anymore, but I made a custom library which allows you to change star dimension programatically (among other stuff): SimpleRatingBar.
It features:
android:layout_width
: it can be set to wrap_content
, match_parent
or abritary dp.In your case, you would just have to do:
ratingbar.setStarSize(20, Dimension.DP);
or, for example, in pixels:
ratingbar.setStarSize(100, Dimension.PX);
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.+'
Upvotes: 1