android学习笔记九——RatingBar
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的更多相关文章
- Android学习笔记九:Service
一:Service是什么 Service,服务.一般用于提供需要在后台长期运行的服务(如复杂计算.下载等等耗时任务),其特点是长生命周期的.没有用户界面.在后台运行的. 二:Service的生命周期方 ...
- 【转】Pro Android学习笔记(九八):BroadcastReceiver(2):接收器触发通知
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.sina.com.cn/flowingflying或作者@恺风Wei-傻瓜与非傻瓜 广播接 ...
- 【转】 Pro Android学习笔记(九二):AsyncTask(1):AsyncTask类
文章转载只能用于非商业性质,且不能带有虚拟货币.积分.注册等附加条件.转载须注明出处:http://blog.csdn.net/flowingflying/ 在Handler的学习系列中,学习了如何h ...
- 【转】 Pro Android学习笔记(六九):HTTP服务(3):HTTP POST MultiPart
目录(?)[-] 建立测试环境 开发环境导入第三方JAR HTTP Post Multipart小例子 HTTP POST不仅可以通过键值对传递参数,还可以携带更为复杂的参数,例如文件.HTTP Po ...
- 【转】 Pro Android学习笔记(二九):用户界面和控制(17):include和merge
目录(?)[-] xml控件代码重用include xml控件代码重用merge 横屏和竖屏landsacpe portrait xml控件代码重用:include 如果我们定义一个控件,需要在不同的 ...
- 【转】 Pro Android学习笔记(十九):用户界面和控制(7):ListView
目录(?)[-] 点击List的item触发 添加其他控件以及获取item数据 ListView控件以垂直布局方式显示子view.系统的android.app.ListActivity已经实现了一个只 ...
- 【转】Pro Android学习笔记(二三):用户界面和控制(11):其他控件
目录(?)[-] Chronometer计时器控件 倒计时CountDownTimer Switch控件 Space控件 其他控件 Android提供了很多控件,基本上都是view的扩展. Chron ...
- 【转】Pro Android学习笔记(二五):用户界面和控制(13):LinearLayout和TableLayout
目录(?)[-] 布局Layout 线性布局LinearLayout 表格布局TableLayout 布局Layout Layout是容器,用于对所包含的view进行布局.layout是view的子类 ...
- 【转】 Pro Android学习笔记(二二):用户界面和控制(10):自定义Adapter
目录(?)[-] 设计Adapter的布局 代码部分 Activity的代码 MyAdapter的代码数据源和构造函数 MyAdapter的代码实现自定义的adapter MyAdapter的代码继续 ...
随机推荐
- 修改Myecclipse servlet/jsp的默认模板
点击图片下载模板: 用winrar等打开myeclipse安装目录下的com.genuitec.eclipse.wizards*.jar,替换响应文件. 详细版:http://www.cnblogs. ...
- HttpResponse的Close和End 区别
转载自:http://blog.sina.com.cn/s/blog_702c390c0100mlhi.html 最近启用了IIS上的压缩功能,但是测试系统上某模块变得不可用了.该模块采用AJAX技术 ...
- csu 1604 SunnyPig (bfs)
Description SunnyPig is a pig who is much cleverer than any other pigs in the pigpen. One sunny morn ...
- ZOJ 1205 Martian Addition
原题链接 题目大意:大数,20进制的加法计算. 解法:convert函数把字符串转换成数组,add函数把两个大数相加. 参考代码: #include<stdio.h> #include&l ...
- leetcode之链表排序题
原文链接:点击打开链接 原题是这样的: Given a linked list and a value x, partition it such that all nodes less than x ...
- 【转】 WebService到底是什么?
WebService到底是什么? http://blog.csdn.net/wooshn/article/details/8069087/
- Python笔记本
Python 的主提示符( >>> )和次提示符( ... ).主提示符是解释器告诉你它在等你输入下一个语句,次提示符告诉你解释器正在等待你输入当前语句的其它部分. 下划线(_)在解 ...
- 《剑指Offer》之替换空格
1.题目描述 请实现一个函数,将一个字符串中的空格替换成"%20".例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy. 2.代码实 ...
- Flash pixel Bender学习笔记
pixel Bender是指用来创建,编译,测试和导出pixel shader,用于各种flash产品的一个IDE. Pixel Bender是Adobe推出的一个高性能的图像视频处理技术.它能跨平台 ...
- ps调色技能
色相/饱和度: 色相->当你看到一种颜色,你会很快的辨别他为什么颜色,比如说红色,绿色,黄色.选中某种颜色然后调整色相. 饱和度->色彩艳丽程度. 明度->调整图片暗亮 曲线:暗亮调 ...