android_ratingBar
主文件
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的更多相关文章
随机推荐
- delphi中使用词霸2005的动态库XdictGrb.dll实现屏幕取词
近日来,在网上发现关于屏幕取词技术的捷径,搜索很长时间,发现实现方式以VB出现的居多,但是通过Delphi来实现的却好象没有看到,自己参考着VB的相关代码琢磨了一下通过delphi来实现的方式. 其实 ...
- android x86 7.0 32bit调试apk时出现的错误
detected problems with app native libraries libavcodec.so:text relocationslibavutil.solibswresample. ...
- ubuntu下建立golang的build脚本
在不在os中设置gopath,goroot的情况下 建立build.sh文件,文件内容如下: export GOARCH="386"export GOBIN="/home ...
- 芒果TV For Windows10 成长历史 & 迭代历史 & 新闻报道
芒果TV 是国内领先的基于Windows10操作系统并支持Windows10全系列设备的视频应用和内容服务商. Win10商店版<芒果TV>是湖南快乐阳光互动娱乐传媒有限公司专门为Wind ...
- C++ GUID和string转化函数【转载】
原文地址:https://blog.csdn.net/zgl7903/article/details/5488294 因为这两个函数太好用,解决了大问题,我必须转载一下了.转自csdn牛人 zgl79 ...
- Mysql下载(on windows-noinstall zip archive)
所有内容,都是针对Mysql5.7.18介绍. 1.首先你需要下载一个完整的包,Mysql目前有两个版本可以使用: a. MySql Enterprise Edition:企业版 b. MySql C ...
- CKEditor 4.5 beta 发布,可视化 HTML 编辑器
分享 <关于我> 分享 [中文纪录片]互联网时代 http://pan.baidu.com/s/1qWkJfcS 分享 <HTML开发MacOSAp ...
- 知识的内化:学习、实践、输出(与Focus Feedback FixIt的原理是一致的)
一个人的能力分三个层次: 资源,比如知识.技能.经验.时间.精力.金钱.人脉等 应用流程,即使用资源解决问题的能力,包括做事的方法.流程.策略等,它是你整合应用资源创造价值的能力. 价值取向,即你觉得 ...
- 监控打印机(使用OpenPrinter,WaitForPrinterChange API函数)
uses Winapi.WinSpool; procedure TForm1.Button1Click(Sender: TObject);varpi2: PRINTER_INFO_2;hPrinter ...
- http 报错码对应的错误原因
转:http://blog.csdn.net/cutbug/article/details/4024818 1xx - 信息提示这些状态代码表示临时的响应.客户端在收到常规响应之前,应准备接收一个或多 ...