Android development-RatingBar control, androidratingbar

Source: Internet
Author: User

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>

:






Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.