Android RatingBar 的用法

 1 package com.turbo;
2
3 import android.app.Activity;
4 import android.os.Bundle;
5 import android.widget.RatingBar;
6 import android.widget.Toast;
7
8 public class AndroidSeekBar extends Activity {
9 @Override
10 protected void onCreate(Bundle savedInstanceState) {
11 super.onCreate(savedInstanceState);
12 setContentView(R.layout.seek_bar);
13 final RatingBar ratingBar_Small = (RatingBar)findViewById(R.id.ratingbar_small);
14 final RatingBar ratingBar_Indicator = (RatingBar)findViewById(R.id.ratingbar_Indicator);
15 final RatingBar ratingBar_default = (RatingBar)findViewById(R.id.ratingbar_default);
16 ratingBar_default.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
17
18 @Override
19 public void onRatingChanged(RatingBar ratingBar, float rating,
20 boolean fromUser) {
21 ratingBar_Small.setRating(rating);
22 ratingBar_Indicator.setRating(rating);
23 Toast.makeText(AndroidSeekBar.this, "rating:" + String.valueOf(rating), Toast.LENGTH_LONG).show();
24 }
25 });
26 }
27
28 }

 

 1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:layout_width="fill_parent"
4 android:layout_height="fill_parent"
5 android:orientation="vertical" >
6 <RatingBar
7 android:layout_width="wrap_content"
8 android:layout_height="wrap_content"
9 style="?android:attr/ratingBarStyleIndicator"
10 android:id="@+id/ratingbar_Indicator"
11 />
12 <RatingBar
13 android:layout_width="wrap_content"
14 android:layout_height="wrap_content"
15 style="?android:attr/ratingBarStyleSmall"
16 android:id="@+id/ratingbar_small"
17 android:numStars="20"
18 />
19 <RatingBar
20 android:layout_width="wrap_content"
21 android:layout_height="wrap_content"
22 style="?android:attr/ratingBarStyle"
23 android:id="@+id/ratingbar_default"
24 />
25 </LinearLayout>



posted @ 2012-03-15 18:33  疯子FK  阅读(2792)  评论(0编辑  收藏  举报