Rating¶
Quick start¶
<com.ave.vastgui.tools.view.ratingview.RatingView
android:id="@+id/ratingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Select method¶
Rating currently supports three select method:
-
Sliding
The rating can be set by sliding or calling
setStarRating
. -
Click
Click behavior changes
Starting from version 0.5.6, when the select method is set to
Click
, the selected number of stars can only be an integer.The rating can be set by clicking or calling
setStarRating
. -
Unable
The rating can only be set by calling
setStarRating
.
mBinding.ratingView.setStarSelectMethod(RatingSelectMethod.SLIDING)
<com.ave.vastgui.tools.view.ratingview.RatingView
...
app:star_select_method="click" />
Orientation¶
Rating currently supports two orientations:
- HORIZONTAL
- VERTICAL
mBinding.ratingView.setStarOrientation(StarOrientation.HORIZONTAL)
<com.ave.vastgui.tools.view.ratingview.RatingView
...
app:star_orientation="horizontal" />
StarOrientation.UNSPECIFIED
The default value of star orientation is StarOrientation.UNSPECIFIED
, and the direction can only be modified once by calling setStarOrientation
or star_orientation
.
Gap¶
mBinding.ratingView.setStarIntervalWidth(10F.DP)
Image¶
The image of star can be set by setStarSelectedBitmap
and setStarUnselectedBitmap
.
mBinding.ratingView.apply{
setStarSelectedBitmap(R.drawable.ic_star_normal)
setStarUnselectedBitmap(R.drawable.ic_star_unselected)
}
Size¶
The size of the star image can be set by setStarBitMapSize
.
mBinding.ratingView.setStarBitMapSize(40F.DP,40F.DP)
Number¶
The number of star can be set by setStarCountNumber
.
mBinding.ratingView.setStarCountNumber(4)
Listener¶
Register a listener by calling setOnStarRatingChangeListener
to observe the rating changes.
mBinding.ratingView.setOnStarRatingChangeListener(object : RatingView.OnStarRatingChangeListener {
override fun onRatingChanged(rating: Float) {
mLogger.d("Current rating is $rating")
}
})