主文件

package cn.com.sxp;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.TextView;

public class RatingBarActivity extends Activity implements OnRatingBarChangeListener{
private RatingBar smallRatingBar = null;
private RatingBar indicatorRatingBar = null;
private TextView ratingText = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ratingText = (TextView) findViewById(R.id.textView);
indicatorRatingBar = (RatingBar) findViewById(R.id.rbFour);
smallRatingBar = (RatingBar) findViewById(R.id.rbThree);

// The different rating bars in the layout. Assign the listener to us.
((RatingBar)findViewById(R.id.rbOne)).setOnRatingBarChangeListener(this);
((RatingBar)findViewById(R.id.rbTwo)).setOnRatingBarChangeListener(this);
}

@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// getNumStars
// Returns the number of stars shown.
final int numStars = ratingBar.getNumStars();
ratingText.setText(" 欢迎程度 " + rating + "/" + numStars);
if (indicatorRatingBar.getNumStars() != numStars) {
indicatorRatingBar.setNumStars(numStars);
smallRatingBar.setNumStars(numStars);
}
// getRating
// Gets the current rating 评级(number of stars filled).
if (indicatorRatingBar.getRating() != rating) {
Log.d("sxp","rating " + rating);
indicatorRatingBar.setRating(rating);
smallRatingBar.setRating(rating);
}
// getStepSize
// Gets the step size of this rating bar.
final float ratingBarStepSize = ratingBar.getStepSize();
if (indicatorRatingBar.getStepSize() != ratingBarStepSize) {
Log.d("sxp","ratingBarStepSize " + ratingBarStepSize);
indicatorRatingBar.setStepSize(ratingBarStepSize);
smallRatingBar.setStepSize(ratingBarStepSize);
}
}
}

XML文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:paddingLeft="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RatingBar android:id="@+id/rbOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="3"
android:rating="2.5" />
<RatingBar android:id="@+id/rbTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="2.25" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip">

<TextView android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<RatingBar android:id="@+id/rbThree"
style="?android:attr/ratingBarStyleSmall"
android:layout_marginLeft="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />

</LinearLayout>
<RatingBar android:id="@+id/rbFour"
style="?android:attr/ratingBarStyleIndicator"
android:layout_marginLeft="5dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />

</LinearLayout>

运行效果;

android_ratingBar的更多相关文章

随机推荐

  1. Android 查看App冷启动时间/热启动时间/页面打开时间

    Android 查看App冷启动时间/热启动时间/页面打开时间 冷启动时间 热启动时间 页面打开时间 通过adb查看 adb shell am start -W packageName/Activit ...

  2. miniui autocomplete支持放大镜按钮(data-grid)

    <style type="text/css"> html body .searchbox .mini-buttonedit-close { background:url ...

  3. 【C++】小心使用文件读写模式:回车('\r') 换行('\n')问题的一次纠结经历

    原来没有仔细注意C++读写文件的二进制模式和文本模式,这次吃了大亏.(平台:windows  VS2012) BUG出现: 写了一个程序A,生成一个文本文件F保存在本地,然后用程序B读取此文件计算MD ...

  4. Mono.Cecil - 0.6

    原文:Mono.Cecil - 0.6 项目地址:Mono.Cecil 项目描述:In simple English, with Cecil, you can load existing manage ...

  5. C# Lambda表达式Contains方法 like

    原文:Lambda表达式Contains方法 like 1.使用Contains方法的必备条件: Contains等价于SQL中的like语句.不过Contains只针对于字符串(string)类型的 ...

  6. DELPHI之关于String的内存分配(引)

    在函数.过程或者方法中定义一个字符串变量时,由于我们知道在函数.过程或者方法中定义的变量为局部变量,它的内存 是在栈中分配的,但是这里有个小细节我们要注意,对于一个局部的字符串变量,它的大小为4字节, ...

  7. 设置tablewidget自适应列宽和设置自动等宽

      在网上很容易知道自适应列宽,100%不留空显示,这里还是提下: /*设置表格是否充满,即行末不留空*/ ui->tableWidget->horizontalHeader()-> ...

  8. 【数据结构】30、hashmap=》hash 计算方式

    前提知识 写在前面,为什么num&(length - 1) 在length是2的n次幂的时候等价于num%length n - 1意味着比n最高位小的位都为1,而高的位都为0,因此通过与可以剔 ...

  9. 修改系统的shell

    一:修改系统的shell     (选用zsh解释器,相对于bash,对它有很好的兼容性,而且功能上更加强大)    1.查看系统中安装的shell      cat  /etc/shells     ...

  10. spring 5.x 系列第20篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (代码配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置类为com.heibaiyin ...