【Android】自定义 View 系列实战篇-View

QRatingView

A custom view for rating which easy to make and use, but function is excellent.
github-QRatingView

Effect Picture

Screenshot_20211203-144523

Properties

    <declare-styleable name="QRatingView">
        <!-- 未选中图片 -->
        <attr name="normalIcon" format="reference"/>
        <!-- 选中图片 -->
        <attr name="selectedIcon" format="reference"/>
        <!-- 自定义评分数量 -->
        <attr name="totalCount" format="integer"/>
        <!-- 选中的个数 -->
        <attr name="selectedCount" format="integer"/>
        <!-- 图案的间隙 -->
        <attr name="gap" format="dimension"/> // Default Size is 5dp
        <!-- 图案的大小 -->
        <attr name="iconSize" format="dimension"/> // Default Size is 25dp
        <!-- 是否可用 不可用时用于仅展示 -->
        <attr name="available" format="boolean"/> // Default value is true
    </declare-styleable>

Usage

for displaying

You are supposed to set tow properties, available and selectedCount. And available should be set as false.
you can use it in .xml

    <com.yeqingqing.qratingview.QRatingView
        android:id="@+id/main_qrv"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:available="false" // if just for displaying ,there are should be false
        app:iconSize="40dp"
        app:selectedCount="3"
        app:totalCount="5" />

also it also will be work in java

   main_qrv2.available = false
   main_qrv2.selectedCount = 5
   

for rating

In this case, we need to set totalCount in .xml and add A selected Lisntener for result

    <com.yeqingqing.qratingview.QRatingView
        android:id="@+id/qrv_main3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:iconSize="40dp" 
        app:totalCount="5" />
     findViewById<QRatingView>(R.id.qrv_main3).setOnSelectedListener(object :
            QRatingView.OnSelectedListener {
            override fun onSelected(selectedCount: Int) {
                when (selectedCount) {
                //todo any reaction for rating
                    1 -> commence1.text = "很差"
                    2 -> commence1.text = "有待改进"
                    3 -> commence1.text = "还行"
                    4 -> commence1.text = "不错"
                    5 -> commence1.text = "非常可以"
                }
            }

        })
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Q-CODER

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值