主文件

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. Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化

    原文:Win8 Metro(C#)数字图像处理--2.57一维最大熵法图像二值化  [函数名称] 一维最大熵法图像二值化WriteableBitmap EntropymaxThSegment(Wr ...

  2. 图像Stride求取

    原文:图像Stride求取 做这个日志也许你会觉得多余,但是,如果只给你了图像的流文件,和图像的Width,让你还原原始图像,那么你会发现一个问题,就是Stride未知的问题,这时就需要根据图像的Wi ...

  3. UWP显示对话框

    public static async void ShowMessage(string message) { var msgDialog = new Windows.UI.Popups.Message ...

  4. C#跳转语句

    1.break 退出直接封闭它的switch.while.do.for或foreach语句. 当有嵌套时,break只退出最里层的语句块. break不能跳出finally语句块. 2.continu ...

  5. Change Default Route

    route delete 0.0.0.0route add 0.0.0.0 mask 0.0.0.0 10.226.4.14

  6. Westciv Tools主要为CSS3提供了渐变gradients、盒子阴影box-shadow、变形transform和文字描边四种在线生成效果的工具

    Westciv Tools主要为CSS3提供了渐变gradients.盒子阴影box-shadow.变形transform和文字描边四种在线生成效果的工具 1.Westciv Tools 彩蛋爆料直击 ...

  7. Qt 5.6.2 静态编译(VS2013 x86 target xp openssl icu webkit)

    在去年4月份的时候,我写过一篇动态编译Qt5.6.0的文章,当时是为了解决webkit不能在winxp下面跑的问题,动态编译有一个缺点,就是发布的时候,要携带一大堆dll,使安装包的体积增大.而静态编 ...

  8. Z Order of Controls in Delphi FireMonkey(Tom Yu的博客)

    Get and set the Z Order of controls at runtime in Delphi FireMonkey. This is a follow on to my earli ...

  9. <iOS小技巧> 返回上级目录操作Goback()方法

    Goback()方法功能:返回上一级界面,通过判断 popViewControllerAnimated 类型是否为空,来判断是present还是pop出来,然后直接做了releaseSelf操作: - ...

  10. Qt中由表中单元格的QModelIndex获取Global Pos的正确方法

    一直在尝试从单元格的行列索引(QModelIndex)获取其单元格的全局坐标(Global Pos)的方法,以期待在指定单元格附近弹出帮助信息.由View中的columnViewportPositio ...