MaterialRatingBar


Source link: https://github.com/DreaminginCodeZH/MaterialRatingBar

MaterialRatingBar

Material Design RatingBar with 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_width is set to match_parent, as in Google Play Store.
  • Able to scale correctly when layout_height is set to values other than 16dp, 36dp and 48dp.
  • Able to display ratings such as 4.3 correctly, which will be filled to 4.5 by 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.2.0'

Usage

Simply replace your RatingBar with 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 RatingBar take 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:minHeight and android:maxHeight that controls the drawable height.

You can checkout more small or indicator variants in styles.xml.

You can use app:mrb_fillBackgroundStars to control whether background stars are filled, otherwise it defaults to the same value as android:isIndicator which is the behavior of Google apps.

8 tint-related attributes such as app:mrb_progressTint and app:mrb_progressTintMode are 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 OnRatingChangeListener interface 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 RatingBar uses 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 framework Widget.Material.RatingBar.Indicator have 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 RatingBar gives erroneous rendering for RatingBar when layout_width is set to match_parent by 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_parent will 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 AbsSeekBar). 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.

License

Copyright 2016 Zhang Hai  Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 

Resources

An implementation of Cassowary, a linear constraint based layout manager for Android.

Adapter and LayoutManager for Android RecyclerView which enables sticky header positioning.

A Library to show Round ImageView with Face Detection and text labels on right side. Best suited for person details.

OAuth RxJava extension for Android.

This library helps to display overlapping views (topmost) in order to show some kind of message to capture user attention. It can be an error, success message, loading bar or just simple text message.

This is a set of classes with a small, extensible API which provides basic abstractions for building your apps using VIPER architecture.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes