Android base controls use of Ratingbar star rating bar

Source: Internet
Author: User

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

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.