自定义View 实现圆形seekbar (音量旋钮)

自定义圆形seekbar

在做一个音频的项目,想在网上找一个圆形aseekbar,但是一直没找到合适的,只好自己动手写了,上网找了一个demo进行了大修改效果如下

效果图

jian的图片

jian的图片

废话不多说,直接上源码,不懂的可以留言

attrs.xml

<resources>

    <declare-styleable name="DutyView">


    <attr name="viewType">

    <enum name="progress" value="0"/>

    <enum name="thumb" value="1"/>

</attr>
    <attr name="initDuty" format="integer"/>
    <attr name="progressBgColor" format="color"/>

    <attr name="progressColor" format="color"/>

    <attr name="arcWidth" format="dimension"/>

    <attr name="textColor" format="color"/>

    <attr name="textSize" format="dimension"/>

</declare-styleable>
</resources>

DutyView.java

public class DutyView extends ViewGroup implements OnTouchListener {
   
    int width;
    int height;
    /**
     * duty最大值
     */
    public static final int MAX_DUTY = 60;
    public int getMaxDuty() {
        return MAX_DUTY;
    }
    /**
     * duty当前值
     */
    private int duty;

    public int getDuty() {
        return duty;
    }

    public void setDuty(int value) {
        if (value >= 0 && value <= MAX_DUTY) {
            duty = value;
            calculateThumbPosition();
            postInvalidate();
            MyBaseActivity.sendMessage(duty+"");
        }
    }

    public void addDuty() {
        if (duty < MAX_DUTY) {
            duty++;
            calculateThumbPosition();
            postInvalidate();

            MyBaseActivity.sendMessage("add"+1);
        }
    }

    public void cutDuty() {
        if (duty > 0) {
            duty--;
            calculateThumbPosition();
            postInvalidate();
            MyBaseActivity.sendMessage("cut"+1);
        }
    }

    /**
     * 文本大小
     */
    private float textSize;

    public float getTextSize() {
        return textSize;
    }

    public void setTextSize(float textSize) {
        this.textSize = textSize;
    }

    /**
     * 文本颜色
     */
    public static final int DEFAULT_TEXT_COLOR = 0xff326ee9;
    private int textColor = DEFAULT_TEXT_COLOR;
    public void setTextColor(int color) {
        this.textColor = color;
        postInvalidate();
    }
    public int getTextColor() {
        return this.textColor;
    }
    /**
     * 圆弧颜色
     */
    public static final int DEFAULT_PROGRESS_BG_COLOR = 0xffffffff;
    private int progressBgColor = DEFAULT_PROGRESS_BG_COLOR;
    public int getProgressBgColor() {
        return progressBgColor;
    }
    public 
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 12
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 12
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值