1、xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RatingBar
android:id="@+id/describe_rb"
style="@style/Custom_commont_RatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="0"
android:stepSize="1.0" />
<TextView
android:id="@+id/describe_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dip"
android:padding="20dip"
android:text="值"
android:textSize="50sp" />
<Button
android:id="@+id/exit_login"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="确定"
android:textColor="#ffffff"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
2、activity
package com.evaluation.demo;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;
public class MainActivity extends Activity {
private RatingBar describe_rb;// 描述
private TextView describe_tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_evaluation);
getXmlView();
}
private void getXmlView() {
describe_rb = (RatingBar) findViewById(R.id.describe_rb);
describe_tv = (TextView) findViewById(R.id.describe_tv);
this.findViewById(R.id.exit_login).setOnClickListener(new onclick());
describe_rb.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
final float score = describe_rb.getRating();
String ss = String.format("%1.0f", score);
describe_tv.setText(ss + "分");
}
});
}
class onclick implements OnClickListener {
@Override
public void onClick(View v) {
final float score = describe_rb.getRating();
if (score == 0) {
Toast.makeText(MainActivity.this, "请评分", Toast.LENGTH_LONG).show();
return;
}
String ss = String.format("%1.0f", score);
Toast.makeText(MainActivity.this, ss, Toast.LENGTH_SHORT).show();
}
}
}
3、style
<style name="Custom_commont_RatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingbar_add</item>
<item name="android:minHeight">30dip</item>
<item name="android:maxHeight">40dip</item>
</style>