Android Development Ratingbar Controls

Source: Internet
Author: User

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

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.