Android 自定义View实现带进度的下载按钮

转载请注明出处:https://blog.csdn.net/a512337862/article/details/80612225

因为项目需要,所以用自定义View实现了带进度条的下载按钮。效果图如下:
这里写图片描述

思路

主要是分为三个阶段:未下载,正在下载,下载结束(成功/失败)。根据不同的进度来判断不同的状态,从而绘制不同的UI。

代码

attr.xml

    <declare-styleable name="DownloadProgressButton">
        <attr name="textColor" format="color" />
        <attr name="textSize" format="dimension" />
        <attr name="progressColor" format="color" />
        <attr name="bottomColor" format="color" />
        <attr name="topColor" format="color" />
        <attr name="progressWidthPercent" format="integer" />
    </declare-styleable>

DownloadProgressButton.java

/**
 * Author : BlackHao
 * Time : 2018/5/18 10:25
 * Description : 自定义带圆形进度条下载控件
 * Remarks :
 */

public class DownloadProgressButton extends View implements View.OnClickListener {
   

    /**
     * 未下载
     */
    public static final int READY_TO_DOWNLOAD = 0;
    /**
     * 正在下载
     */
    public static final int IS_DOWNLOADING = 1;
    /**
     * 下载完成
     */
    public static final int FINISH_DOWNLOAD = 2;
    /**
     * 下载失败
     */
    public static final int FAIL_DOWNLOAD = 3;
    //进度最大值
    private int max;
    //当前进度
    private int progress;
    //进度条的颜色
    private int progressColor;
    //进度条宽度百分比
    private int progressWidthPercent;
    //底层背景色
    private int bottomColor;
    //最上层圆的颜色
    private int topColor;
    //进度文本的颜色
    private int textColor;
    //进度文本的字体大小
    private int textSize;
    //进度条画笔
    private Paint progressPaint;
    //文本画笔
    private Paint textPaint;
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值