RatingBar的使用方法

通过学习RatingBar升级控件的学习,总结使用步骤如下:
1、在layout目录下创建main.xml布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
<RatingBar
android:id="@+id/ratingbarId"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:numStars="5"//设置多少个评级
android:stepSize="1.0"//设置进度评级的点数
/>
</LinearLayout>
2、创建一个MainActivity继承Activity
package com.ratingbar;

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

public class MainActivity extends Activity {
    private RatingBar ratingBar = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ratingBar = (RatingBar)findViewById(R.id.ratingbarId);
        ratingBar.setOnRatingBarChangeListener(new RatingBarListener());
    }
   
    private class RatingBarListener implements RatingBar.OnRatingBarChangeListener{
//监听评级控件改变时,都会调这个方法
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
System.out.println("rating--->" + rating);
}
    }
}

你可能感兴趣的:(android,RatingBar,xml,layout,LinearLayout)