Android development-RatingBar control, androidratingbar
The RatingBar control provides you with a scoring operation mode.
Common Methods of controls:
1. setMax ()
Set the maximum value of the RatingBar star slider.
2. setNumStars ()
Set 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. If it is set to fill_parent, the number of displayed stars may not be the number of configured stars.
3. setRating ()
Set the display score of the RatingBar star slider and the number of stars.
4. setStepSize ()
Set the minimum length (Min number of stars) for each change of the RatingBar star slider ). For example, setStepSize (float) 0.5) is half a star.
5. setOnRatingBarChangeListener ()
Set the listener. After the user changes the slider, the listener is triggered.
Demo instance:
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 bar. setMax (100); // set the score bar. setRating (float) 1.5); // sets the minimum length bar for each change. setStepSize (float) 0.5); // sets the 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>
: