Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android star rating how to fit to width

I need a star rating bar that can fit to width auto. When I try to resize on design screen; if screen is small some stars disappears (after 5th or 6th), if screen with is big all stars are visible.

How do I do it?

here is what do I have

<RatingBar
    android:id="@+id/ratingBar1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:numStars="10"
    android:rating="7" />
like image 938
fobus Avatar asked Sep 04 '13 20:09

fobus


1 Answers

U can't set width but you can use custom Rating bar, just add :

compile 'FlexibleRatingBar:flexibleratingbar:1.3'

This rating bar will fit automatically. Than you initialize for example:

ratingBar = new FlexibleRatingBar(this);
    ratingBar.setStepSize(1);
    ratingBar.setColorFillOn(Color.rgb(65,105,225));
    ratingBar.setColorFillPressedOn(Color.rgb(135,206,235));
someLayout.addView(ratingBar);
like image 162
milosnkb Avatar answered Sep 29 '22 22:09

milosnkb