首页 > 代码库 > Android --RatingBar的使用

Android --RatingBar的使用

1.效果图

 

2.代码

main.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/LL"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <RatingBar        android:id="@+id/ratingBar1"        android:layout_width="wrap_content"        android:layout_height="wrap_content" >    </RatingBar></LinearLayout>

firstActivity.java

final RatingBar mRating = (RatingBar) findViewById(R.id.ratingBar1); // 获取对象        mRating.setMax(100); // 设置最大值        mRating.setNumStars(5); // 设置星型数量        mRating.setStepSize((float) 0.5); // 设置步长        mRating.setRating((float) 3.5);                mRating.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {            @Override            public void onRatingChanged(RatingBar ratingBar, float rating,                    boolean fromUser) {                // TODO Auto-generated method stub                a = mRating.getRating();// 设置当前分数                Toast.makeText(firstActivity.this, "当前的分数为:" + a * 20,                        Toast.LENGTH_SHORT).show();            }        });

 



 

Android --RatingBar的使用