自定义圆形seekbar
在做一个音频的项目,想在网上找一个圆形aseekbar,但是一直没找到合适的,只好自己动手写了,上网找了一个demo进行了大修改效果如下
效果图
废话不多说,直接上源码,不懂的可以留言
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