主文件

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. 生成view的描述字段列表

    ); declare @field_list nvarchar(max); set @table = N'vwMaterial'; set @field_list = N''; SELECT u.na ...

  2. C语言实现的CRC16/CCITT-FALSE校验码函数

    要求:输入字符串“00 AA FF CC AA 01 00” 得到校验码“79B1” 方法1: // ConsoleApplication1.cpp: 定义控制台应用程序的入口点. // #inclu ...

  3. 通过NLayer和NAudio转换MP3成WAV

    NuGet安装: Install-Package NLayer.NAudioSupport 示例代码: using Microsoft.Win32; using NAudio.Wave; using ...

  4. 把握每次机会,麒麟芯片5年成就高端(SoC包括AP、基带、ISP等,华为确实牛)

    从2016年11月华为Mate 9 /Mate 9 Pro发布,到2017年2月荣耀V9和华为P10 /P10 Plus 相继发布,这几款都是华为和荣耀的高端旗舰机型,且搭载的都是华为最新旗舰芯片-- ...

  5. Window文件目录遍历 和 WIN32_FIND_DATA 结构(非常详细的中文注释)

    第一部分     *百度百科提供的内容总结:WIN32_FIND_DAT 第二部分   *程序实例 第三部分   *一篇使用FindFirstFile和FindNextFile函数的博文   第一部分 ...

  6. MinGW版Qt如何搭建lua环境?(详细步骤)

    操作系统是windows,lua是Lua for Windows 5.1.4包含了这三个头文件 <ignore_js_op>  在.pro里加了includepath: <ignor ...

  7. SYN1610型B码时统设备

       SYN1610型B码时统设备 产品概述 SYN1610型B码时统设备是由西安同步电子科技有限公司精心设计.自行研发生产的一款模块化配置的通用性时统终端,可接收北斗/ GPS信号/ IRIG-B码 ...

  8. gitlab安装笔记二_Centos7配置163yum源

    进入配置目录 cd  /etc/yum.repos.d 压缩备份原有的配置 sudo tar cvf  base.tar.gz   *.repo 可以解压查看备份 sudo tar xvf base. ...

  9. ElasticSearch搜索引擎的入门实战

    1.ElasticSearch简介 引用自百度百科: ElasticSearch是一个基于Lucene的搜索服务器.它提供了一个分布式多用户能力的全文搜索引擎,基于RESTful web接口.Elas ...

  10. netty服务端启动--ServerBootstrap源码解析

    netty服务端启动--ServerBootstrap源码解析 前面的第一篇文章中,我以spark中的netty客户端的创建为切入点,分析了netty的客户端引导类Bootstrap的参数设置以及启动 ...