星级评分条(RatingBar)的功能和用法
星级评分条与拖动条有相同的父类:AbsSeekBar,因此它们十分相似。实际上星级评分条与拖动条的用法、功能都十分接近;它们都是允许用户通过拖动条来改变进度。RatingBar与SeekBar最大区别在于;RatingBar通过星星来表示进度。
为了让程序能响应星级评分条评分的改变,程序可以考虑为它绑定一个OnRatingBarChangeListener监听器。
下面通过一个实例来示范RatingBar的功能和用法。
实例:通过星级改变图片的透明度
该程序其实只是前一个程序的简单改变,只是将上面程序中的SeekBar组件改为使用RatingBar。下面是界面布局中关于RatingBar的代码片段。
界面布局文件如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="240dp"
android:src="@drawable/lijiang"/> <!-- 定义一个星级评分条 -->
<RatingBar android:id="@+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:max="255"
android:progress="255"
android:stepSize="0.5" /> </LinearLayout>
上面的布局文件中指定了该星级评分条的最大值为255,当前进度为255——其中两个属性都来自于ProgressBar组件,这没有任何问题,因为RatingBar本来就是一个特殊的ProgressBar。
主程序只要为RatingBar绑定事件监听器即可,监听星级评分条的星级改变。
package org.crazyit.helloworld; import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ImageView;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener; public class RatingBarTest extends Activity {
RatingBar ratingBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rating_bar_test);
ratingBar=(RatingBar)findViewById(R.id.rating);
final ImageView image=(ImageView)findViewById(R.id.image);
ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){ @Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
//动态改变图片的透明度,其中255是星级评分条的最大值
//5个星星就代表最大值255
image.setAlpha((int)(rating*255/5));
} });
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.rating_bar_test, menu);
return true;
} }

星级评分条(RatingBar)的功能和用法的更多相关文章
- Android基础控件RatingBar星级评分条的使用
1.简介 RatingBar继承ProgressBar,除了ProgressBar的属性外还有特有属性: android:isIndicator:是否用作指示,用户无法更改,默认false andro ...
- Android中点击按钮获取星级评分条的评分
场景 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为Lin ...
- 星级评分进度条(RatingBar)
星级评分进度条(RatingBar):(主要用于评价等方面) 常用的xml属性; android:isIndicator:RatingBar是否是一个指示器(用户无法进行更改) android:num ...
- Android 自学之星级评分条RatingBar
星级评分条(RatingBar)与拖动条十分相似,他们还有共同的父类AbsSeekBar.实际上星级评分条和拖动条的用法和功能都十分的接近:他们都允许用户通过拖动来改变进度.RatingBar与See ...
- 星级评分条(RatingBar)的功能与用法
星级评分条与拖动条有相同的父类:AbsSeekBar,因此它们十分相似.实际上星际评分条与拖动条的用法.功能都十分接近:它们都允许用户通过拖动来改变进度.RatingBar与SeekBar的最大区别在 ...
- IOS-一步一步教你自定义评分星级条RatingBar ——转载的
由于项目的需要,需要设计能评分.能显示评分数据的星级评分条,但是IOS上好像没有这个控件,Android是有RatingBar这个控件的(又发现一个IOS不如Android好的),那就只能自定义了,在 ...
- IOS-一步一步教你自定义评分星级条RatingBar
本文转载至 http://blog.csdn.net/hanhailong726188/article/details/42344131 由于项目的需要,需要设计能评分.能显示评分数据的星级评分条,但 ...
- Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar
原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...
- ProgressBar(进度条)、SeekBar(拖动条)与星级评分条(RatingBar)
1.ProgressBar(进度条) (1)介绍 (2)常用属性 (3)xml代码 <ProgressBar android:id="@+id/progressBar2" s ...
随机推荐
- Enterprise Architect与startUML表示UML常用图
转自:http://www.cnblogs.com/alexlee73/archive/2011/11/05/2237294.html 附下载地址:http://download.csdn.net/d ...
- B. Qualifying Contest
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- 皓轩的jquery mobile之路(二)
jQuery Mobile 使用 HTML5 & CSS3 最小的脚本来布局网页. 编写代码要注意最外层div需要添加data-role="page" ,标题需要添加dat ...
- 在Delphi中使用C++对象(转)
源:http://blog.csdn.net/henreash/article/details/7352335 Delphi是市场上最好的RAD工具,但是现在C++占据着主导地位,有时针对一个问题很难 ...
- 64位系统访问注册表SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
public int ChecNonkWoW64() { try { ; string subKey = @"SOFTWARE\Microsoft\Windows\CurrentVersio ...
- spring加载过程中jar包加载不了,解决方法
当我们在开发spring项目时,一般会将jar包放到webInf/lib下,这样是myeclipse自动将jar包加载到tomcat中webapps下,但是当我们新建一个lib文件夹的情况下,我们ad ...
- Spring第一个例子的补充
1.首先导入需要的包: 2.文件结构: 3.先看xml配置文件: <?xml version="1.0" encoding="UTF-8"?> &l ...
- Tengine TCP 负载均衡
tar jxvf jemalloc-3.5.1.tar.bz2 cd jemalloc-3.5.1 ./configure make && make install echo '/us ...
- JS表单原生验证器
一.前言 最近在开发一个新项目,需要做登陆等一系列的表单提交页面.在经过“缜密”的讨论后,我们决定 不用外部流行的框架,如bootstrap,由于我负责的模块 仅仅是其中的一部分,因此少数服从多数,无 ...
- CodeForces 625A Guest From the Past
贪心水题 #include <stdio.h> #include <algorithm> #include <string.h> #include <queu ...