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