星级评分条与拖动条有相同的父类: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)的功能和用法的更多相关文章

  1. Android基础控件RatingBar星级评分条的使用

    1.简介 RatingBar继承ProgressBar,除了ProgressBar的属性外还有特有属性: android:isIndicator:是否用作指示,用户无法更改,默认false andro ...

  2. Android中点击按钮获取星级评分条的评分

    场景 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 获取编程相关电子书.教程推送与免费下载. 实现 将布局改为Lin ...

  3. 星级评分进度条(RatingBar)

    星级评分进度条(RatingBar):(主要用于评价等方面) 常用的xml属性; android:isIndicator:RatingBar是否是一个指示器(用户无法进行更改) android:num ...

  4. Android 自学之星级评分条RatingBar

    星级评分条(RatingBar)与拖动条十分相似,他们还有共同的父类AbsSeekBar.实际上星级评分条和拖动条的用法和功能都十分的接近:他们都允许用户通过拖动来改变进度.RatingBar与See ...

  5. 星级评分条(RatingBar)的功能与用法

    星级评分条与拖动条有相同的父类:AbsSeekBar,因此它们十分相似.实际上星际评分条与拖动条的用法.功能都十分接近:它们都允许用户通过拖动来改变进度.RatingBar与SeekBar的最大区别在 ...

  6. IOS-一步一步教你自定义评分星级条RatingBar ——转载的

    由于项目的需要,需要设计能评分.能显示评分数据的星级评分条,但是IOS上好像没有这个控件,Android是有RatingBar这个控件的(又发现一个IOS不如Android好的),那就只能自定义了,在 ...

  7. IOS-一步一步教你自定义评分星级条RatingBar

    本文转载至 http://blog.csdn.net/hanhailong726188/article/details/42344131 由于项目的需要,需要设计能评分.能显示评分数据的星级评分条,但 ...

  8. Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar

    原文:Android零基础入门第53节:拖动条SeekBar和星级评分条RatingBar 前面两期都在学习ProgressBar的使用,关于自定义ProgressBar的内容后期会继续学习的,本期先 ...

  9. ProgressBar(进度条)、SeekBar(拖动条)与星级评分条(RatingBar)

    1.ProgressBar(进度条) (1)介绍 (2)常用属性 (3)xml代码 <ProgressBar android:id="@+id/progressBar2" s ...

随机推荐

  1. 模仿 app

    原文链接:http://www.jianshu.com/p/a634b66cb180 前言 作为一个IOS程序员,闲的时候也想自己做一个app练练手,又苦于没有UI设计,也没有好的idea,所以只能先 ...

  2. 安装tomcat过程中出现问题小结

    报错信息如下:Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these ...

  3. Python大神成长之路: 第一次学习记录

    一.Python发展史 二.Python2 or 3 博主选择了Python3. 从官网下载Python  www.python.org Windows安装python3.5.python2.7.安装 ...

  4. IDEA github的应用

    1.下载并安装一个git 一直点下一步就可以 2.去github官网注册一个账号 https://github.com/ 2.1点击Sign up 进入注册页面 2.2填写注册信息,点击Create ...

  5. 2016"百度之星" - 资格赛(Astar Round1) Problem B

    规律题,斐波那契数列,数据有毒,0的时候输出换行.会爆longlong,写个大数模板或者Java搞. import java.io.BufferedInputStream; import java.m ...

  6. 操作IFRAME及元素

    内容里有两个ifame <iframe id="leftiframe"...</iframe> <iframe id="mainiframe..& ...

  7. mrql初级教程-概念、使用(一)

    以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 感谢您支持我的博客,我的动力是您的支持和关注!如若转载和使用请注明转载地址 ...

  8. SQL Server 2012 - Transact-SQL

    变量 --全局变量 select @@VERSION --局部变量 declare @i int set @i=5 select @i 通配符:   like   'joh%',  %任意长度的任意字 ...

  9. CodeForces 754D Fedor and coupons (优先队列)

    题意:给定n个优惠券,每张都有一定的优惠区间,然后要选k张,保证k张共同的优惠区间最大. 析:先把所有的优惠券按左端点排序,然后维护一个容量为k的优先队列,每次更新优先队列中的最小值,和当前的右端点, ...

  10. 苹果App Store开发者帐户从申请,验证,到发布应用(3)

    应用上架的流程和操作步骤 下面主要介绍一下,上架应用相关流程和相关的操作步骤:   1.登录itunes,https://itunesconnect.apple.com/WebObjects/iTun ...