一.简单概述


1.相关属性:

> android:isIndicator:是否用作指示,用户无法更改,默认false
> android:numStars:显示多少个星星,必须为整数 android:rating:默认评分值,必须为浮点数
> android:stepSize: 评分每次增加的值,必须为浮点数
> android:progressBackgroundTint="@color/goCart_btn" :未选中星星的颜色
> android:progressTint="@color/goCart_btn"  :选中星星的颜色
> android:secondaryProgressTint="@color/goCart_btn"  :选中星星的边框颜色

还有两种样式供我们选择

>  style="?android:attr/ratingBarStyleIndicator"
>  style="?android:attr/ratingBarStyleSmall"

2.实现代码

  <TextViewandroid:id="@+id/item_tv"android:text="星级评分"android:textSize="16sp"android:layout_width="wrap_content"android:layout_height="wrap_content"/><RatingBarandroid:rating="3.3"android:numStars="5"android:layout_width="wrap_content"android:layout_height="wrap_content"/><RatingBarstyle="?android:attr/ratingBarStyleIndicator"android:rating="3.3"android:numStars="5"android:layout_width="wrap_content"android:layout_height="wrap_content"/><RatingBarandroid:layout_marginTop="10dp"android:layout_marginLeft="5dp"style="?android:attr/ratingBarStyleSmall"android:rating="3.3"android:numStars="5"android:layout_width="wrap_content"android:layout_height="wrap_content"/>

二.如何修改选中星星的颜色

 <RatingBarandroid:rating="4.3"android:numStars="5"android:progressTint="#ffeca011"android:secondaryProgressTint="#ffeca011"android:progressBackgroundTint="#ffe7e7e7"android:layout_width="wrap_content"android:layout_height="wrap_content"/>

三.示例展示

1.xml文件

这三行是一样的,所以就给出一行代码

 <RelativeLayoutandroid:id="@+id/star_describe"android:layout_width="match_parent"android:layout_height="wrap_content"><TextViewandroid:id="@+id/score_title1"android:layout_alignParentLeft="true"android:layout_centerVertical="true"android:text="描述相符"android:textSize="13sp"android:textColor="@color/theme_defaultText"android:layout_width="wrap_content"android:layout_height="wrap_content"/><TextViewandroid:id="@+id/describe_tip"android:textSize="12sp"android:textColor="@color/theme_textColor"android:layout_marginLeft="5dp"android:layout_toRightOf="@+id/score_title1"android:layout_centerVertical="true"android:layout_width="wrap_content"android:layout_height="wrap_content"/><RatingBarandroid:id="@+id/describe_score"android:layout_alignParentRight="true"style="@style/Widget.AppCompat.RatingBar.Indicator"android:isIndicator="false"android:progressTint="@color/goCart_btn"android:progressBackgroundTint="@color/eval_default_star"android:secondaryProgressTint="@color/goCart_btn"android:numStars="5"android:stepSize="1"android:layout_width="wrap_content"android:layout_height="wrap_content"/></RelativeLayout>
2.java代码
//监听值的变化private void ratingBarListener() {describe_score.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {@Overridepublic void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {String score = String.valueOf(rating);scoreState1 = fun_getScoreState(score);describe_tip.setText(scoreState1);}});}
//根据分数转换成文字展示private String fun_getScoreState(String score) {String rating = "";switch (score) {case "1.0":rating = "差";break;case "2.0":rating = "较差";break;case "3.0":rating = "一般";break;case "4.0":rating = "好";break;case "5.0":rating = "极好";break;}return rating;}

android中星级评分控件RatingBar的使用相关推荐

  1. android星星评分,Android星星评分控件RatingBar的使用

    在Android的开发中,有一个叫做评分控件RatingBar,我们可以使用该控件做等级划分.评分等作用,星星形状显示,也可以半星级别,我们来看一下评分控件如何使用. 布局文件中定义控件以及属性,这里 ...

  2. Android中的基础控件TextView、Button、ImageView、EditText、ProgressBar

    文章目录 1 Android中的基础控件 1.1 控件的通用属性 2 TextView 2.1 TextView的继承关系 2.2 TextView的常用属性 3 EditText 3.1 常用属性 ...

  3. Android中进度条控件使用

    android中进度条控件使用 ProgressBar pb = findViewById(R.id.pb);pb.setMax(100);pb.setProgress(33); 转载于:https: ...

  4. 从零开始学android:Android中的基本控件(上)

    从零开始学android:Android中的基本控件(上) 本章内容较多,下面只贴代码,大家只需要贴到自己eclipse里就知道作用^^! View组件简介 Android中的View组件包含了几乎所 ...

  5. android ratingbar不可点击,Android评分控件RatingBar使用实例解析

    无论游戏,应用,网站,都少不了评分控件.在Android SDK 中提供了 RatingBar控件来实现相应的工作. 标签有几个常用评分相关属性 android:numStars,指定评分五角星数. ...

  6. 星星评价控件android开发_android自定义星级评分控件,可实现只显示实心星星

    话不多说,上图 近日app需求弄一个等级展示,看了下UI图,只显示实星(点亮的星星).如图 但是网上关于星级评分的例子大多这样 也展示虚心星星 通过自定义Viewpackage com.starsba ...

  7. android 中使用TabHost控件实现微信界面的底部菜单效果

    首先,在布局文件中的代码如下:(菜单位于底部,需要在代码中设置) <TabHostandroid:id="@android:id/tabhost"android:layout ...

  8. Android中的基础控件CheckBox、RadioButton、ToggleButton、SeekBar

    文章目录 1 CheckBox 1.1 CheckBox介绍 2 RadioButton 2.1 RadioButton介绍 3 ToggleButton 3.1 ToggleButton介绍 4 S ...

  9. android中互斥的控件,Android控件之Radiobutton与RadioGroup

    RadioButton 是一个单选控件,在一个RadioGroup中,各个RadioButton是互斥的 XML文件: xmlns:tools="http://schemas.android ...

最新文章

  1. 影像组学视频学习笔记(18)-使用MRIcroGL软件格式转换、勾画ROI、Li‘s have a solution and plan.
  2. Kubernetes是什么
  3. 暴力技术(一)——BFS广(宽)度优先搜索
  4. pip install mysqlclient 报错:error: Microsoft Visual C++ 14.0 is required.
  5. java的本质_Java线程本质
  6. 现代通信原理思维导图--第三章 随机过程
  7. [4G+5G专题-145]: 一体化小基站- 5G小基站软件建议架构概述
  8. css通过行内样式绑定背景图片
  9. oracle和timesten整合,Oracle TimesTen 关系型内存数据库18.1新版本详解
  10. JS前端生成二维码的几种方式
  11. 「Wekan」- 看板工具 @20210403
  12. 微信小程序picker-view中的view的高度修改问题,只能用px单位
  13. KVM虚拟化进阶--KVM设备高级管理
  14. 肥宅快乐还是不快乐,拓展欧几里得,exgcd???bfs
  15. 音乐 组件 (音频, 视频)
  16. 什么是黑盒测试和白盒测试、灰盒测试?
  17. C语言取模运算符的妙用
  18. 进入BeOS的花花世界 系列五
  19. XML详细入门教程[PDF]
  20. 大连软交会开幕 人工智能成热点话题

热门文章

  1. 计算机教案在幻灯片中插入影片,小学信息技术《在幻灯片中插入艺术字》说课稿...
  2. Web经典BS快速开发框架,强大后台+简洁UI一体化开发工具
  3. 1905影音播放器 v4.0.0 官方版
  4. 华为交换机维护助手配置案例-定时任务自动ping测
  5. 工程师什么时机最合适选择跳槽?
  6. 面试机试之坐标转换问题
  7. 计算机二级access用什么版本,二级access-计算机二级access考试时用哪个版本的???微信- 爱问知识人...
  8. 九联UNT413A-S905L3A-免拆U盘卡刷固件包-当贝纯净桌面-内有教程
  9. 老外说中国姓氏^_^
  10. k8s admission webhook初探