以不同方式自定义 RatingBar 星星
Customize RatingBar stars differently
我正在尝试自定义 RatingBar
中的每颗星,使其看起来不同。
我看它的源码RatingBar or its super classes AbsSeekBar / ProgressBar,我无法识别这个选项,它只能为整个View提供一个progress/secondaryProgress和背景。最接近的是使用 thumbDrawable,但它的用途完全不同(不确定 SeekBar
)。
除了做一个完全自定义的视图来复制这样的功能之外,还有什么选择吗?
这是我尝试创建的带有 RatingBar 的图片:
我不得不提的是,每颗星(最后选择的星)都会有不同的 "face",并且总是恰好有 5 颗星(numStars
属性)。非常感谢任何想法!
看看这个库 starBar by badoo 有 1 到 10 个星星,颜色不同,如红橙黄绿,您可以更改资源中的图像以选择栏。
此 link 也会有所帮助。
您可以使用SmileView that provides rating view with different drawables for each rating value and also is based on badoo's StarBar view
用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
...
<com.eugeneek.smilebar.SmileBar
android:id="@+id/starBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:smileWidth="50dp"
app:smileHeight="50dp"
app:smileDefault="@drawable/none"
app:smileRate1="@drawable/one"
app:smileRate2="@drawable/two"
app:smileRate3="@drawable/three"
app:smileRate4="@drawable/four"
app:smileRate5="@drawable/five"
app:horizontalSpacing="8dp"
app:rating="1"
app:enabled="true"/>
...
</LinearLayout>
我正在尝试自定义 RatingBar
中的每颗星,使其看起来不同。
我看它的源码RatingBar or its super classes AbsSeekBar / ProgressBar,我无法识别这个选项,它只能为整个View提供一个progress/secondaryProgress和背景。最接近的是使用 thumbDrawable,但它的用途完全不同(不确定 SeekBar
)。
除了做一个完全自定义的视图来复制这样的功能之外,还有什么选择吗?
这是我尝试创建的带有 RatingBar 的图片:
我不得不提的是,每颗星(最后选择的星)都会有不同的 "face",并且总是恰好有 5 颗星(numStars
属性)。非常感谢任何想法!
看看这个库 starBar by badoo 有 1 到 10 个星星,颜色不同,如红橙黄绿,您可以更改资源中的图像以选择栏。 此 link 也会有所帮助。
您可以使用SmileView that provides rating view with different drawables for each rating value and also is based on badoo's StarBar view
用法
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
...
<com.eugeneek.smilebar.SmileBar
android:id="@+id/starBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:smileWidth="50dp"
app:smileHeight="50dp"
app:smileDefault="@drawable/none"
app:smileRate1="@drawable/one"
app:smileRate2="@drawable/two"
app:smileRate3="@drawable/three"
app:smileRate4="@drawable/four"
app:smileRate5="@drawable/five"
app:horizontalSpacing="8dp"
app:rating="1"
app:enabled="true"/>
...
</LinearLayout>