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的更多相关文章
随机推荐
- C#如何在VS2015 2017版本中编写WPF UI界面引入第三方SVG图形
原文:C#如何在VS2015 2017版本中编写WPF UI界面引入第三方SVG图形 在VS2015 2017版本中编写WPF UI界面引入第三方SVG图形 最近在写WPF界面的时候遇到一个情 ...
- sqlserver检查sql执行时间
set statistics profile onset statistics io onset statistics time onGO select * from mytable; goset s ...
- Creating a Linux Daemon (service) in Delphi
With the introduction of the Linux target for Delphi, a wide range of possibilities are opened up to ...
- vim文本编辑器的基本使用方法
前言 命令模式与编辑模式 内置命令 参考资料注明 前言 vi命令是UNIX操作系统和类UNIX操作系统中最通用的全屏幕纯文本编辑器.Linux中的vi编辑器叫vim,它是vi的增强版(vi Impro ...
- orm单表操作
二.orm简介 ORM:object relation mapping (ORM是“对象-关系-映射”的简称) MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦, ...
- dedecms自学
[dedecms笔记] index.htm 主页模板head.htm 列表头部模板footer.htm ...
- No.595-Big Countries-(LeetCode之Database篇)
数据库表 给出的数据库表如下,表名为World. +-----–+----+----+----–+-----+ | name | continent | area | ...
- MyBatis从入门到精通(三):MyBatis XML方式的基本用法之多表查询
最近在读刘增辉老师所著的<MyBatis从入门到精通>一书,很有收获,于是将自己学习的过程以博客形式输出,如有错误,欢迎指正,如帮助到你,不胜荣幸! 1. 多表查询 上篇博客中,我们示例的 ...
- CI框架使用(一)
CI框架的使用是很简单,也 是mvc模式.其中有好多类直接调用. 在使用帮助函数的时候,都需要手动加载,或者是在配置文件中加一个自动加载 $this->load->helper('ur ...
- Go - Struct 结构体
目录 概述 声明结构体 生成 JSON 改变数据 推荐阅读 概述 结构体是将零个或多个任意类型的变量,组合在一起的聚合数据类型,也可以看做是数据的集合. 声明结构体 //demo_11.go pack ...