RatingBar==>星级评分条

RatingBar和SeekBar十分相似,它们甚至有相同的父类:AbsSeekBar.两者都允许用户通过拖动来改变进度;

两者最大的区别在于RatingBar是通过星星表示进度;RatingBar本身就是一个特殊的SeekBar。

RatingBar常见XML属性如下图:

注意:为了程序支持响应星级评分条的改变,程序可以考虑为其绑定一个OnRatingBarChangeLinstener监听器。

实例如下:

布局文件==》
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" > <!-- <ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="200px"
android:src="@drawable/no" />--> <RatingBar
android:id="@+id/ratingbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:max="255"
android:numStars="5"
android:progress="255"
android:stepSize="0.5" /> </RelativeLayout> 代码实现==》
package com.example.myratingbar; 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 MainActivity extends Activity
{ @Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); RatingBar bar = (RatingBar) this.findViewById(R.id.ratingbar);
//final ImageView img = (ImageView) this.findViewById(R.id.image); bar.setOnRatingBarChangeListener(new OnRatingBarChangeListener()
{
@SuppressWarnings("deprecation")
@Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser)
{
//img.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.main, menu);
return true;
} }

实现效果如:

如何替换如上图系统默认星星图标,实现方式如下:

参考:http://my.oschina.net/amigos/blog/60060

drawable-mdpl资源文件==》

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item
android:id="@+android:id/background"
android:drawable="@drawable/unselect">
</item>
<item
android:id="@+android:id/secondaryProgress"
android:drawable="@drawable/unselect">
</item>
<item
android:id="@+android:id/progress"
android:drawable="@drawable/select">
</item> </layer-list>

 样式文件==》style.xml

 <style name="roomRatingBar" parent="@android:style/Widget.RatingBar">
<item name="android:progressDrawable">@drawable/ratingbar_drawable</item>
<item name="android:minHeight">48dip</item>
<item name="android:maxHeight">48dip</item>
</style>

加 布局文件==》

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" > <RatingBar
android:id="@+id/ratingbar"
style="@style/roomRatingBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dip"
android:numStars="8"
android:rating="1.5"
android:stepSize="0.15" /> </LinearLayout>

运行效果如下:

  

android学习笔记九——RatingBar的更多相关文章

  1. Android学习笔记九:Service

    一:Service是什么 Service,服务.一般用于提供需要在后台长期运行的服务(如复杂计算.下载等等耗时任务),其特点是长生命周期的.没有用户界面.在后台运行的. 二:Service的生命周期方 ...

  2. 【转】Pro Android学习笔记(九八):BroadcastReceiver(2):接收器触发通知

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.sina.com.cn/flowingflying或作者@恺风Wei-傻瓜与非傻瓜 广播接 ...

  3. 【转】 Pro Android学习笔记(九二):AsyncTask(1):AsyncTask类

    文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 在Handler的学习系列中,学习了如何h ...

  4. 【转】 Pro Android学习笔记(六九):HTTP服务(3):HTTP POST MultiPart

    目录(?)[-] 建立测试环境 开发环境导入第三方JAR HTTP Post Multipart小例子 HTTP POST不仅可以通过键值对传递参数,还可以携带更为复杂的参数,例如文件.HTTP Po ...

  5. 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge

    目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...

  6. 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView

    目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...

  7. 【转】Pro Android学习笔记(二三):用户界面和控制(11):其他控件

    目录(?)[-] Chronometer计时器控件 倒计时CountDownTimer Switch控件 Space控件 其他控件 Android提供了很多控件,基本上都是view的扩展. Chron ...

  8. 【转】Pro Android学习笔记(二五):用户界面和控制(13):LinearLayout和TableLayout

    目录(?)[-] 布局Layout 线性布局LinearLayout 表格布局TableLayout 布局Layout Layout是容器,用于对所包含的view进行布局.layout是view的子类 ...

  9. 【转】 Pro Android学习笔记(二二):用户界面和控制(10):自定义Adapter

    目录(?)[-] 设计Adapter的布局 代码部分 Activity的代码 MyAdapter的代码数据源和构造函数 MyAdapter的代码实现自定义的adapter MyAdapter的代码继续 ...

随机推荐

  1. dalvik虚拟内存管理之三——调试信息

    转载自http://www.miui.com/thread-75063-1-1.html 1. verbosegc一般Java虚拟机要求支持verbosegc选项,输出详细的垃圾收集调试信息.dalv ...

  2. webStorm快捷键总结

    Ctrl+Shift+a:快速查找使用编辑器所有功能1.左侧栏目录显影:Ctrl+Shift+F122.文件模板配置:File>Settings>Editor>File and Co ...

  3. 1.PHP站内搜索 分类: PHP开发实例 2015-07-31 22:48 4人阅读 评论(0) 收藏

    PHP站内搜索:多关键字.加亮显示 1.SQL语句中的模糊查找 $sql = "SELECT * FROM `message` WHERE `content`like '%$k[0]%' a ...

  4. HDU 1312 Red and Black --- 入门搜索 BFS解法

    HDU 1312 题目大意: 一个地图里面有三种元素,分别为"@",".","#",其中@为人的起始位置,"#"可以想象 ...

  5. 创建kafkatopic和productor

    cd 到kafka 目录下 创建topic create topicbin/kafka-topics.sh --zookeeper spark1:2181,spark2:2181,spark3:218 ...

  6. JS 排序算法

    冒泡排序: 核心思想:从第一个开始遍历数组,遍历完成后,让最小的值放在第一位:然后从第二个开始遍历数组,遍历完成后将最小值放在第二位:以此类推,所有位的数组遍历完成后就排序完成. var arr = ...

  7. kuangbin_ShortPath F (POJ 3259)

    判环模板题 有了上一题的经验过得很轻松 除了因为spfa还不是很熟打错了两个字母 然后debug了一小会 #include <iostream> #include <string&g ...

  8. 黑马程序员——JAVA基础之包,权限

    ------- android培训.java培训.期待与您交流! ---------- 包(package) 对类文件进行分类管理. 给类提供多层命名空间. 写在程序文件的第一行. 类名的全称的是:包 ...

  9. 内存使用空间之swap建置[转]

    http://www.cnblogs.com/ggjucheng/archive/2012/08/22/2651502.html 内存置换空间(swap)之建置 安装时一定需要的两个 partitio ...

  10. web开发注意的问题

    1.<input type="submit" value="提交">    将表单提交<form action="login.jsp ...