Android <RatingBar scoring component. 23.> and androidratingbar learning from scratch
If you want to rate an application, you will often use the components shown in the figure to determine the final score by selecting the number of "five-pointed stars" in Android, you can use the RatingBar component. This component can be used to facilitate user input. The definition structure of the RatingBar class is as follows: java. lang. object upload android. view. view every android. widget. progressBar upload android. widget. absSeekBar uses android. widget. ratingBar common RatingBar Methods
1 |
Public RatingBar (Context context) |
Structure |
|
Create a RatingBar object |
2 |
Public int getNumStars () |
Normal |
|
Scored quantity |
3 |
Public float getRating () |
Normal |
|
Get Current Value |
4 |
Public float getStepSize () |
Normal |
|
Get the set step size |
5 |
Public boolean isIndicator () |
Normal |
|
Determine whether operation is allowed |
6 |
Public void setIsIndicator (boolean isIndicator) |
Normal |
Android: isIndicator |
Can be operated? |
7 |
Public synchronized void setMax (int max) |
Normal |
|
Set the maximum value |
8 |
Public void setNumStars (int numStars) |
Normal |
Android: numStars |
Set the number of stars |
9 |
Public void setOnRatingBarChangeListener (RatingBar. OnRatingBarChangeListener listener) |
Normal |
|
Set operation listening |
10 |
Public void setRating (float rating) |
Normal |
Android: rating |
Set Current Value |
11 |
Public void setStepSize (float stepSize) |
Normal |
Android: stepSize |
Set the step size for each increase |
XML file
<RelativeLayout 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: paddingBottom = "@ dimen/activity_vertical_margin" android: paddingLeft = "@ dimen/plugin" android: paddingRight = "@ dimen/plugin" android: paddingTop = "@ dimen/activity_v Ertical_margin "tools: context = ". mainActivity "> <RatingBar android: id =" @ + id/ratingBar1 "android: numStars =" 5 "// set the maximum number of android devices: rating = "3" // initial number android: stepSize = "0.5" // set the step size android: isIndicator = "false" // you can operate android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_alignParentTop = "true" android: layout_centerHorizontal = "true" android: layout_marginTop = "90dp"/> <TextView Ndroid: id = "@ + id/textView1" android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_below = "@ + id/ratingBar1" android: layout_centerHorizontal = "true" android: layout_marginTop = "70dp" android: textAppearance = "? Android: attr/textAppearanceMedium "/> </RelativeLayout>
JAVA files
Package com. example. ratingbar; import org. w3c. dom. text; import android. OS. bundle; import android. app. activity; import android. widget. ratingBar; import android. widget. ratingBar. onRatingBarChangeListener; import android. widget. textView; public class MainActivity extends Activity {private RatingBar ratingBar; private TextView textView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); ratingBar = (RatingBar) this. findViewById (R. id. ratingBar1); textView = (TextView) this. findViewById (R. id. textView1); // sets the listener method ratingBar. listener (new OnRatingBarChangeListener () {@ Overridepublic void onRatingChanged (RatingBar ratingBar, float rating, boolean fromUser) {// TODO Auto-generated method stub // textView append display data // textView. append ("*** current value:" + rating + "** step:" + ratingBar. getStepSize () + "\ n"); // The switch case statement is used to determine the number of stars evaluated. The corresponding operation switch (int) rating) {case 1: textView. setText ("current user rating: Too bad"); break; case 2: textView. setText ("current user rating: Not good"); break; case 3: textView. setText ("current user rating: Good"); break; case 4: textView. setText ("current user rating: Good"); break; case 5: textView. setText ("current user rating: Great"); break; default: break ;}}});}}
First display
Case statement to determine the Display Effect
The scoring component allows users and software developers to provide good feedback and express their opinions on some issues.
Next prediction: Several event processing methods
Android RatingBar: how to get a star in the Activity class without using xml --
Drawable db = this. getResources (). getDrawable (R. drawable. xxx. xml );
Rb. setProgressDrawable (db );
Rb. setIndeterminateDrawable (db );
For xxx. xml, see ratingbar_small.xml in frameworks.
Bytes -----------------------------------------------------------------------------------------------------
Answers from the android team
Welcome to the android excellent team!
How do I set the minimum RatingBar score?
Android: rating // default rating, which must be of the floating point type, such as "1.2 ".