1. Introduction
Ratingbar inherits ProgressBar, except for properties that are unique to ProgressBar:
// Event Handling
2. Easy to use
1) drawable Resource layer-list layer of the star bar:
<?XML version= "1.0" encoding= "Utf-8"?><layer-listxmlns:android= "Http://schemas.android.com/apk/res/android"> <ItemAndroid:id= "@android: Id/background"android:drawable= "@drawable/rating_off"/> <ItemAndroid:id= "@android: id/progress"android:drawable= "@drawable/rating_on"/></layer-list>
2) Add a style to the Styles.xml file under the Values folder:
<stylename= "Roomratingbar_1"Parent= "@android: Style/widget.ratingbar"> <Itemname= "Android:progressdrawable">@drawable/ratingbar_layer</Item> <Itemname= "Android:minheight">24dip</Item> <Itemname= "Android:maxheight">24dip</Item> </style>
3) XML layout file for the Star bar:
<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:gravity= "Center"android:orientation= "vertical"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context=". Loginactivity "> <RatingbarAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:id= "@+id/ratingbar"style= "@style/roomratingbar_1"Android:isindicator= "false"Android:numstars= "6"android:rating= "1.5"android:stepsize= "0.25"/></LinearLayout>
4) Java file event handling:
Public classLoginactivityextendsappcompatactivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_login); //Set up the login form.Ratingbar Ratingbar=(Ratingbar) Findviewbyid (R.id.ratingbar); Ratingbar.setonratingbarchangelistener (NewRatingbar.onratingbarchangelistener () {@Override Public voidOnratingchanged (Ratingbar Ratingbar,floatVBooleanb) {toast.maketext (loginactivity). This, "rating" +string.valueof (v), Toast.length_short). Show (); } }); }}
Android base controls use of Ratingbar star rating bar