控件: RatingBar
显示:TextView
方法: RatingBar.setOnRatingBarChangeListener类的onRatingChanged()方法。
XML:
<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" >
<RatingBar
android:id="@+id/ratingBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:numStars="4"
android:rating="2.25"
android:stepSize="0.25" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="16dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="@+id/ratingBar1"
android:contentDescription="@string/rating_text"
android:text="@string/rating_text" />
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ratingBar1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="37dp" />
</RelativeLayout>
代码:
//进度条值的获取与显示
public void showUserScroe() {
RatingBar rate = (RatingBar) findViewById(R.id.ratingBar1);
rate.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
((TextView) findViewById(R.id.textView1)).setText("Rating: "+ rating);
}
});
}
//计时器
private static final String DEBUG_TAG = "Bar data.";
public void timerStart() {
final Chronometer timer = (Chronometer) findViewById(R.id.chronometer1);
long base = timer.getBase();
Log.d(DEBUG_TAG, "base = "+ base);
timer.setBase(0);
timer.start();
}
图示: