This example introduces the usage of RatingBar. RatingBar is a subclass of SeekBar and ProgressBar. It uses pentagram to show the same score. By default, RatingBar users can change the score value by using the direction keys or touch/drag. ratingBarStyleSmall and ratingBarStyleLarge of the other two styles generally do not support user interaction and are used to display the score result.
SetNumStarts can set the number of five-pointed stars in the comment column. Let's take a look at the XML definition in this example:
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: paddingLeft = "10dip"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<RatingBar android: id = "@ + id/ratingbar1 ″
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: numStars = "3 ″
Android: rating = "2.5"/>
<RatingBar android: id = "@ + id/ratingbar2 ″
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: numStars = "5 ″
Android: rating = "2.25"/>
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content"
Android: layout_marginTop = "10dip">
<TextView android: id = "@ + id/rating"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
<RatingBar android: id = "@ + id/small_ratingbar"
Style = "? Android: attr/ratingBarStyleSmall"
Android: layout_marginLeft = "5dip"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"/>
</LinearLayout>
<RatingBar android: id = "@ + id/indicator_ratingbar"
Style = "? Android: attr/ratingBarStyleIndicator"
Android: layout_marginLeft = "5dip"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_gravity = "center_vertical"/>
</LinearLayout>
RatingBar provides an event response score change.
OnRatingChanged (RatingBar ratingBar, float rating, boolean fromTouch)