As anyone who’s used RatingBar knows, it’s a bit of a bummer. It’s hard to adjust size, spacing, colors, styles, and so on. Here is the ultimate solution of RatingBar -AndRatingBar. AndRatingBar open source library, it inherited from Android native RatingBar, RatingBar can also inherit the good tradition of dragging RatingBar, through the internal drawable rewrite to achieve the size can be changed according to the size of the control, and can easily set the color, custom icon and so on. 1. Take a look at the preview:
AndRatingBar can set size, spacing, color, icon, etc., and can display Rating from right to left, and can be used in RecyclerView without exceptions.
2, the use of
Using AndRatingBar is also easy: First add a dependency:
allprojects { repositories { maven { url 'https://jitpack.io' } } } dependencies { implementation 'com. Making. Wsj1024: AndRatingBar: 1.0.6'}Copy the code
Then reference it in the layout
<per.wsj.library.AndRatingBar
android:layout_width="wrap_content"
android:layout_height="48dp"
app:starDrawable="@drawable/star_blue"
app:bgDrawable="@drawable/star_gray"
Copy the code
Event listeners
ratingBar.setOnRatingChangeListener { ratingBar, rating ->
Log.e("ratingBar", "rating:$rating")
}
Copy the code
3, configuration
As mentioned earlier, AndRatingBar inherits from Android’s native RatingBar, so you can use various properties of the native RatingBar, often as follows:
- Android: rating = “1” rating
- Android :numStars=”8″ sets the number of stars
- Android :layout_height=” 36DP “Sets the height of the control
- Android :stepSize=”0.5″ set the stepSize of the Rating
- Android :isIndicator=”true” (code only, not manual)
In addition, AndRatingBar provides extended properties for easy styling:
- App :starDrawable=”” Set the star icon
- App :bgDrawable=”” Set the background icon
- App :starColor=”” set the starColor
- App :subStarColor=”” Sets the secondary color
- App :bgColor=”” Set star background color
- App :keepOriginColor=”” Sets whether to keep the original color of the icon
- App :starSpacing=”4dp” Adjusts the spacing between stars
- App :scaleFactor=”1.2″ Adjusts the spacing between stars by scaling
- App :right2Left=”true” displayed from right to left
Warehouse address: github.com/wsj1024/And… , gitee.com/wangshiju/A… Welcome to star