I\'ve added a RatingBar in a layout:
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
use the following code for small rating bar with onTouch event
enter code here
<RatingBar
android:id="@+id/ratingBar"
style="?android:ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="false"
android:rating="4"
android:stepSize="0.5" />
The Best Answer for small ratingbar
<RatingBar
android:layout_width="wrap_content"
style = "?android:attr/ratingBarStyleSmall"
android:layout_height="wrap_content" />
I found an easier solution than I think given by the ones above and easier than rolling your own. I simply created a small rating bar, then added an onTouchListener to it. From there I compute the width of the click and determine the number of stars from that. Having used this several times, the only quirk I've found is that drawing of a small rating bar doesn't always turn out right in a table unless I enclose it in a LinearLayout (looks right in the editor, but not the device). Anyway, in my layout:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RatingBar
android:id="@+id/myRatingBar"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5" />
</LinearLayout>
and within my activity:
final RatingBar minimumRating = (RatingBar)findViewById(R.id.myRatingBar);
minimumRating.setOnTouchListener(new OnTouchListener()
{
public boolean onTouch(View view, MotionEvent event)
{
float touchPositionX = event.getX();
float width = minimumRating.getWidth();
float starsf = (touchPositionX / width) * 5.0f;
int stars = (int)starsf + 1;
minimumRating.setRating(stars);
return true;
}
});
I hope this helps someone else. Definitely easier than drawing one's own (although I've found that also works, but I just wanted an easy use of stars).
The best answer I got
<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>
user like this
<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" />
Increase/Decrease sizes by using scaleX and scaleY value
Its working for me in rating bar xml style="?android:attr/ratingBarStyleSmall" add this.it will work.