Customizing the display style of Ratingbar

Source: Internet
Author: User

Ratingbar is a control view that we often use in our projects to represent the index of the evaluation. It's a pentagram style, but the style that comes with it is sometimes uncoordinated in our project, and we're going to customize the Ratingbar display style.

First, or write controls on the layout page:

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/my_need_evaluate_linearlayout_top"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:orientation= "Horizontal" >

<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
android:layout_marginleft= "10DP"
android:layout_margintop= "28DP"
android:text= "Please score"
Android:textsize= "22SP"/>

<ratingbar
Android:id= "@+id/my_evaluate_rabar"
style= "@style/myratingbar"
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"

android:layout_marginleft= "10DP"
Android:isindicator= "false"
Android:numstars= "5"
android:rating= "0"
Android:stepsize= "1.0"/>
</LinearLayout>

Where does it change its style? In the layout of the style= "@style/myratingbar", this is a style we have customized:

<style name= "Myratingbar" parent= "@android: Style/widget.ratingbar" >
<item name= "android:progressdrawable" > @drawable/my_evaluate_ratingbar_color</item>
<item name= "Android:minheight" >20dip</item>
<item name= "Android:maxheight" >20dip</item>
<item name= "Android:minwidth" >20dip</item>
</style>

The drawable/my_evaluate_ratingbar_color used in the style above:

<?xml version= "1.0" encoding= "Utf-8"?>
<layer-list xmlns:android= "Http://schemas.android.com/apk/res/android" >

<item
Android:id= "@+android:id/background"
android:drawable= "@drawable/my_star_normal"/>//Normal style
<item
Android:id= "@+android:id/secondaryprogress"
android:drawable= "@drawable/my_star_normal"/>
<item
Android:id= "@+android:id/progress"
android:drawable= "@drawable/my_star_select"/>//This is the style we chose.

</layer-list>

Pictures such as my_star_normal are pictures that let the UI cut.

The use of the activity is simple:

Private Ratingbar Mratingbar; Evaluation level

Mratingbar = (Ratingbar) Findviewbyid (R.id.my_evaluate_rabar);

Mratingbar.setonratingbarchangelistener (Ratingbarlistener);

Private Onratingbarchangelistener Ratingbarlistener = new Onratingbarchangelistener () {

@Override
public void onratingchanged (Ratingbar ratingbar, float rating, Boolean fromuser) {
What you want to do, such as displaying something in a TextView
}

};

Customizing the display style of Ratingbar

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.