相关属性:
android:isIndicator:是否用作指示,用户无法更改,默认false
android:numStars:显示多少个星星,必须为整数
android:rating:默认评分值,必须为浮点数
android:stepSize: 评分每次增加的值,必须为浮点数
<RatingBar android:id="@+id/rb" android:layout_width="match_parent" android:layout_height="wrap_content" android:numStars:"5" android:rating="0.0" android:stepSize="0.5"/>
事件处理:
只需为RatingBar设置OnRatingBarChangeListener事件,然后重写下onRatingChanged()方法即可!
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); rb = (RatingBar) findViewById(R.id.rb); rb.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() { @Override public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) { Toast.makeText(MainActivity.this, "rating"+String.valueOf(rating), Toast.LENGTH_SHORT).show(); } }); }