Android自定义Ratingbar星星实现评分
2017-03-12 12:42
471 查看
由于Android自带的Ratingbar可以改变星星的颜色,但是无法设置间距,所以我们自定义了
Ratingbar
下面是自定义的使用方法:
其定义属性中:
canEdit true 可以点击选择不同的星星,默认false
differentSize 星星的大小可以不同(中间的最大,两端的依次变小且星星总数为奇数时才有效)
dividerWidth 单个星星之间的间隔
starCount 星星的总个数
widthAndHeight 星星的大小
countSelected 已经选择的星星的个数
stateResId单个星星的不同状态,在drawable下:
附上效果图一张
gradle dependency
转载地址:https://github.com/xingliuhua/XLHRatingBar
源码下载:http://download.csdn.net/detail/zhaihaohao1/9778420
Ratingbar
下面是自定义的使用方法:
XLHRatingBar
自定义Ratingbar,与系统提供的RatingBar相比可更方便指定每个星星的图标、大小及各个星星的间距,支持监听选中状态的变化
在xml布局文件中使用:
<com.example.xlhratingbar_lib.XLHRatingBar xmlns:xlhRatingBar="http://schemas.android.com/apk/res-auto" android:id="@+id/ratingBar" android:layout_width="wrap_content" android:layout_height="wrap_content" xlhRatingBar:canEdit="true" xlhRatingBar:differentSize="true" xlhRatingBar:dividerWidth="5dp" xlhRatingBar:countSelected="2" xlhRatingBar:starCount="5" xlhRatingBar:stateResId="@drawable/comment_ratingbar_selector" xlhRatingBar:widthAndHeight="50dp" />
其定义属性中:
canEdit true 可以点击选择不同的星星,默认false
differentSize 星星的大小可以不同(中间的最大,两端的依次变小且星星总数为奇数时才有效)
dividerWidth 单个星星之间的间隔
starCount 星星的总个数
widthAndHeight 星星的大小
countSelected 已经选择的星星的个数
stateResId单个星星的不同状态,在drawable下:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/evaluation_order_star_press" android:state_checked="true"></item> <item android:drawable="@drawable/evaluation_order_star" android:state_checked="false"></item> </selector>
在代码中使用:
XLHRatingBar ratingBar = (XLHRatingBar) findViewById(R.id.ratingBar); ratingBar.setCountNum(5); ratingBar.setCountSelected(1); ratingBar.setOnRatingChangeListener(new XLHRatingBar.OnRatingChangeListener() { @Override public void onChange(int countSelected) { tvResult.setText(countSelected + ""); } });
附上效果图一张
引用
gradle dependencydependencies { compile 'com.xingliuhua:xlhratingbar_lib:1.0.1' }
转载地址:https://github.com/xingliuhua/XLHRatingBar
源码下载:http://download.csdn.net/detail/zhaihaohao1/9778420
相关文章推荐
- Android中自定义RatingBar实现星星大小,数量,间距等的设置
- Android自定义View之自定义评价打分控件RatingBar实现自定义星星大小和间距
- Android中自定义RatingBar实现星星大小,数量,间距等的设置
- Android自定义View实现商品评价星星评分控件
- Android自定义星星评分控件代替RatingBar的使用
- Android UI控件RatingBar实现自定义星星评分效果
- Android自定义View之自定义评价打分控件RatingBar实现自定义星星大小和间距
- Android自定义RatingBar(评分控件)
- Android 自定义ratingBar(评分小星星)的使用
- Android自定义星星评分控件
- Android自定义RatingBar(评分控件)
- Android星星评分控件RatingBar的使用
- Android星星评分控件RatingBar的使用
- Android 自定义RatingBar评分控件
- Android自定义星星评分控件
- 自定义LinearLayout实现RatingBar效果,打造一个评分控件
- 【Android自定义View实战】之自定义评价打分控件RatingBar,可以自定义星星大小和间距
- Android中自定义RatingBar(评分控件)的方法
- Android 自定义星星可滑动评分控件
- Android星星评分控件RatingBar的使用