仿饿了么加入购物车旋转控件 - 自带闪转腾挪动画 的按钮

本文详细介绍了如何实现一个仿饿了么购物车的旋转控件,包括其属性支持、静态绘制以及各种动画效果,如加减按钮的旋转、位移、透明度动画和数量的动画。此外,还讨论了点击事件监听和在列表中正确显示UI的处理方法,提供了源码链接供读者参考和学习。
摘要由CSDN通过智能技术生成

android:layout_height=“wrap_content”

app:count=“3”

app:gapBetweenCircle=“90dp”

app:maxCount=“99”/>

<com.mcxtzhang.lib.AnimShopButton

android:id="@+id/btnEle"

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

app:addEnableBgColor="#3190E8"

app:addEnableFgColor="#ffffff"

app:hintBgColor="#3190E8"

app:hintBgRoundValue=“15dp”

app:hintFgColor="#ffffff"

app:maxCount=“99”/>

注意:

加减点击后,具体的操作,要根据业务的不同来编写了,设计到实际的购物车可能还有写数据库操作,或者请求接口等,要操作成功后才执行动画、或者修改count,这一块代码每个人写法可能不同。

使用时,可以重写onDelClick()onAddClick()方法,并在合适的时机回调onCountAddSuccess()onCountDelSuccess()以执行动画。

效果图如图2.

支持的属性

| name | format | description | 中文解释 |

| :-: | :-: | :-: | :-: |

| isAddFillMode | boolean | Plus button is opened Fill mode default is stroke (false) | 加按钮是否开启fill模式 默认是stroke(false) |

| addEnableBgColor | color | The background color of the plus button | 加按钮的背景色 |

| addEnableFgColor | color | The foreground color of the plus button | 加按钮的前景色 |

| addDisableBgColor | color | The background color when the button is not available | 加按钮不可用时的背景色 |

| addDisableFgColor | color | The foreground color when the button is not available | 加按钮不可用时的前景色 |

| isDelFillMode | boolean | Plus button is opened Fill mode default is stroke (false) | 减按钮是否开启fill模式 默认是stroke(false) |

| delEnableBgColor | color | The background color of the minus button | 减按钮的背景色 |

| delEnableFgColor | color | The foreground color of the minus button | 减按钮的前景色 |

| delDisableBgColor | color | The background color when the button is not available | 减按钮不可用时的背景色 |

| delDisableFgColor | color | The foreground color when the button is not available | 减按钮不可用时的前景色 |

| radius | dimension | The radius of the circle | 圆的半径 |

| circleStrokeWidth | dimension | The width of the circle | 圆圈的宽度 |

| lineWidth | dimension | The width of the line (+ - sign) | 线(+ - 符号)的宽度 |

| gapBetweenCircle | dimension | The spacing between two circles | 两个圆之间的间距 |

| numTextSize | dimension | The textSize of draws the number | 绘制数量的textSize |

| maxCount | integer | max count | 最大数量 |

| count | integer | current count | 当前数量 |

| hintText | string | The hint text when number is 0 | 数量为0时,hint文字 |

| hintBgColor | color | The hint background when number is 0 | 数量为0时,hint背景色 |

| hintFgColor | color | The hint foreground when number is 0 | 数量为0时,hint前景色 |

| hingTextSize | dimension | The hint text size when number is 0 | 数量为0时,hint文字大小 |

| hintBgRoundValue | dimension | The background fillet value when number is 0 | 数量为0时,hint背景圆角值 |

这么多属性够你用了吧。

下面看重点的实现吧,Let’s Go!.

实现解剖


关于自定义View的基础,这里不再赘述。

如果阅读时有不明白的,建议下载源码边看边读࿰

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值