android 组件RatingBar实例

本例子是对RatingBar的练习,RatingBar是评价条控件。类似淘宝上的五星好评。


布局文件:ratingbar_layout.xml



    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


            android:id="@+id/ratingBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />





AtyRatingBar.java文件:


package com.fxj.composit;


import com.fxj.compractice.R;


import android.app.Activity;
import android.os.Bundle;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;


public class AtyRatingBar extends Activity {
private RatingBar ratingBar;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ratingbar_layout);
ratingBar = (RatingBar) findViewById(R.id.ratingBar1);
// 为评价条控件设置改变监听
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
Toast.makeText(AtyRatingBar.this, "评价为:" + rating,
Toast.LENGTH_SHORT).show();
}
});

}


}


运行效果:


android 组件RatingBar实例_第1张图片


结束。

你可能感兴趣的:(android开发学习)