1.回顾

   上篇学习 Android 布局 优化的知识 ,和 SeekBar (可拖动 滚动条)的理解与学习

2.重点

   (1)RatingBar 的实现

   (2)OnRatingBarChangeListener 的实现

3.实现

   3.1 效果图

                                         

Android-基本控件(Ratingbar 实现)_Android

  3.2 布局实现


<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"
tools:context="${relativePackage}.${activityClass}" >

<RatingBar
android:id="@+id/rating_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btn_debug"
android:layout_marginTop="28dp" />

</RelativeLayout>


OnRatingBarChangeListener 实现

      初始化 控件 (findviewById)就不说了;

     使用 Toast 显示

class rating_bar1Listener implements OnRatingBarChangeListener{

@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(this,rating+"颗星星",Toast.LENGTH_SHORT).show();
}
}


  3.4 绑定 监听事件


rating_bar1.setOnRatingBarChangeListener(new rating_bar1Listener());