Google 系应用设计相同、支持拉伸、修正原生实现诸多问题的星级评分条。可直接替换 RatingBar。
2016-10-28 09:15
525 查看
MaterialRatingBar
项目地址:DreaminginCodeZH/MaterialRatingBar简介:与 Google 系应用设计相同、支持拉伸、修正原生实现诸多问题的星级评分条。可直接替换 RatingBar。
Material Design
RatingBarwith better appearance,
compatible with Android 3.0+.
Why MaterialRatingBar?
Consistent appearance on Android 3.0+.Extends framework
RatingBar.
Get the 2dp star border background as in Material Icons and Google apps.
Correct custom tinting across platforms.
Able to render correctly when
layout_widthis set to
match_parent,
as in Google Play Store.
Able to scale correctly when
layout_heightis set to values other than 16dp,
36dp and 48dp.
Able to display ratings such as
4.3correctly, which will be filled to
4.5by
framework's incorrect implementation.
Avoid framework's sunken half star visual glitch.
Used as a drop-in replacement for framework
RatingBar.
Preview
Sample
APK
Integration
Gradle:compile 'me.zhanghai.android.materialratingbar:library:1.0.2'
Usage
Simply replace your RatingBarwith
MaterialRatingBar,
and remember to apply a corresponding style for correct behavior.
For example, to create a normal
MaterialRatingBar:
<me.zhanghai.android.materialratingbar.MaterialRatingBar android:layout_width="wrap_content" android:layout_height="wrap_content" style="@style/Widget.MaterialRatingBar.RatingBar" />
In order to make your
RatingBartake the
correct and consistent size on all versions, you will always need to use one of the styles from this library. The trick inside it is
android:minHeightand
android:maxHeightthat
controls the drawable height.
You can checkout more small or indicator variants in styles.xml
8 tint-related attributes such as
android:mrb_progressTintand
app:mrb_progressTintModeare
also supported so that they can control the tinting of rating drawables. The default tint color is
?colorControlActivated,
and the default tint mode is
src_in.
An
OnRatingChangeListenerinterface is also
added to
MaterialRatingBar, which enables callback while user is dragging, just as the
listener in
SeekBar.
For a detailed example, you can refer to the sample
app's layout, where you can find examples such as tinting and wide layout.
Design
Filled star or star border
The framework's RatingBaruses filling stars
with grey color as track, however as per the Material Icons site, star border icons are given.
And as for the Google Play Store and Google I/O app, they are both using the star borders as track.
With Google's design practice and aesthetic considerations taken into account, I decided to use the star border style.
Star size
Google Play Store has stars of optical size 24dp, while Google I/O app and frameworkWidget.Material.RatingBar.Indicatorhave
stars of size 36dp (which are of optical size 30dp). (The framework's default size of 64dp is ridiculously large and thus not taken into consideration.)
Also noticing that the Material Icons site gives icons of 24dp (optical 20dp) and 36dp (optical 30dp), I decided to stick to the 36dp approach which is also visually pleasant.
Star border width
The ring for radio button in Material Design has a width of 2dp, and with experiments on other border widths, I decided to adopt the 2dp border width.The star border icon is drawn with the help of Inkscape, by downloading the star icon SVG from Material Icons, duplicating the outer border path of the star, setting a stroke of 4dp, running stroke to path on it,
extracting the inner border path, and finally combining this path and the original outer border path.
Wide layout
Framework RatingBargives erroneous rendering
for
RatingBarwhen
layout_widthis
set to
match_parentby tiling the stars without any gap. Since Google Play Store employed
the wide design, I implemented it inside this library as well, so that
match_parentwill
work properly for
MaterialRatingBar.
Dragging
Google Play Store and Google I/O app both used an implementation other than RatingBar,
which means dragging on the bar across stars won't work (it is the functionality of
SeekBar).
I think this is a handy way of interaction for users, and it enables the setting of 0 star which can be useful if you want to enable users to reset their rating to unrated.
相关文章推荐
- 利用Memcached在php下实现session机制 替换PHP的原生session支持
- PNaCl:Google通过LLVM增强对Chrome中原生应用的支持
- js+css实现星级评分(支持小数点后一味)
- 任何国家都无法限制数字货币。为什么呢? 要想明白这个问题需要具备一点区块链的基础知识: 区块链使用的大致技术包括以下几种: a.点对点网络设计 b.加密技术应用 c.分布式算法的实现 d.数据存储技术 e.拜占庭算法 f.权益证明POW,POS,DPOS 原因一: 点对点网络设计 其中点对点的P2P网络是bittorent ,由于是点对点的网络,没有中心化,因此在全球分布式的网
- PNaCl:Google通过LLVM增强对Chrome中原生应用的支持
- 通过调试的重构代码(设计是对的,但是实现过程却有诸多的问题)
- 利用Memcached在php下实现session机制,替换PHP的原生session支持
- DIY Android之一--原生Android系统主题支持的设计和实现(来自本人cnblogs博客)
- 高级别问题:如何在ASP.NET大型应用系统的模块化开发实现多版本程序集并存支持
- 原生JS实现-星级评分系统的简单实例
- 任何国家都无法限制数字货币。为什么呢? 要想明白这个问题需要具备一点区块链的基础知识: 区块链使用的大致技术包括以下几种: a.点对点网络设计 b.加密技术应用 c.分布式算法的实现 d.数据存储技术 e.拜占庭算法 f.权益证明POW,POS,DPOS 原因一: 点对点网络设计 其中点对点的P2P网络是bittorent ,由于是点对点的网络,没有中心化,因此在全球分布式的网
- 原生js实现的星级评分效果
- 原生js实现的星级评分效果
- DIY Android之一--原生Android系统主题支持的设计和实现
- 利用Memcached在php下实现session机制 替换PHP的原生session支持
- 很酷的星级评分系统原生JS实现
- 应用框架的设计与实现——.NET平台4.2代码测试问题解决
- 多段图问题的动态规划算法设计与实现
- 比较高效地实现从两个不同数组中提取相同部分组成新的数组(暂时只支持Int类型)
- 掌握信息 --设计和实现“员工自助服务”的一些重要问题