最近需要做一个星星的评分控件(可以调整进度,进度颜色渐变)
如图:
image
image
一开始想到的是用系统自带的RatingBar做,但发现了一个问题,实现颜色渐变有点复杂,而且有好几个页面都用了这个,总不能都这样写吧。刚好这段时间看了HenCoder写的Android自定义view系列文章,于是就想自己尝试下实现一个评分控件,可以实现图案的替换,渐变颜色,进度背景,图案个数,大小等参数的自己控制,经过几天的折腾,终于完成了这个控件CBRatingBar
先上效果图:
image
image
image
image
gif效果图:
image
如何使用:
Gradle
在项目的build.gradle中添加如下代码:
allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}
在项目的build.gradle中引入该库:
dependencies {
compile 'com.github.CB-ysx:CBRatingBar:2.0.1'
}
使用方法
xml
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:starSize="20dp"
app:starCount="5"
app:starSpace="10dp"
app:starStrokeWidth="1dp"
app:starCanTouch="true"
app:starMaxProgress="120"
app:starProgress="60"
app:starShowStroke="true"
app:starUseGradient="true"
app:starStartColor="#0000ff"
app:starEndColor="#00ff00"
app:starCoverColor="#ff0000"
app:starFillColor="#666666"
app: