The Ratingbar control provides the user with a mode for scoring operations.
Several common ways to control:
1.setMax ()
Sets the maximum value of the Ratingbar star slider.
2.setNumStars ()
Sets the number of stars for the Ratingbar star slider. It is worth noting that the layout width of the control should be set to Wrap_content, and if set to Fill_parent, the number of stars displayed is most likely not the number of stars set.
3.setRating ()
Set the display score of the Ratingbar Star slider and set the number of stars.
4.setStepSize ()
Sets the minimum length (minimum number of stars) for each change of the Ratingbar star slider. such as: Setstepsize ((float) 0.5) is half a star.
5.setOnRatingBarChangeListener ()
Set up the listener. Triggers the listener after the user changes the slider.
Demo Example:
Mainactivity.java
public class Mainactivity extends Activity {ratingbar bar; @Overridepublic void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); bar = (Ratingbar) findViewById (R.id.rat );///The number of stars of the slider Bar.setnumstars (5);//Set the maximum value of Bar.setmax (100);//Set the score bar.setrating ((float) 1.5);// Sets the minimum length for each change bar.setstepsize ((float) 0.5);//Set Listener Bar.setonratingbarchangelistener (new Onratingbarchangelistener () { @Overridepublic void onratingchanged (Ratingbar arg0, float arg1, Boolean arg2) {Toast.maketext (Mainactivity.this, "" + ARG1*20, Toast.length_short). Show ();}});}}
Activity_main.xml
<linearlayout xmlns: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:orientation= "vertical" tools:context= "${relativepackage}.${activityclass}" > < Ratingbar android:id= "@+id/rat" android:layout_width= "wrap_content" android:layout_height= "Wrap_ Content "/> </LinearLayout>
:
Android Development Ratingbar Controls