转载请注明本文地址:
http://blog.csdn.net/springcoder/article/details/52296036
本来最近做一个项目想找个不一样点的progressbar,然后看到了一个四点状的progressbar不过需要金币才能下载,算了反正也写的不是那么的适用,干脆直接自己写一个吧。我写东西喜欢封装的过瘾点,多来点set方法给以后用的人自己set去,于是他们只做了点的我就一定做个既可以空心也可以实心的,还可以改变点的数目颜色的,于是花了一个小时左右的时间,写了这个东东
一。废话不多说,先上效果图
二。具体代码
一。首先自定义一个点
这个点可以是空心的,也可以是实心的,其实就是一个圆圈,在这里我们给他的属性有,颜色,半径,是否是空心的还是实心的,还有空心的那么线条的粗细是多少呢,这里我是写的是用半径除以6 ,看起来效果还不错,嗯就用他了
import android.graphics.Canvas;
import android.graphics.Paint;
import android.icu.text.DateFormat;
/**
* Created by sunshine on 2016/8/23.
*/
public class Dot {
/**
* 圆点的坐标
*/
private double x;
private double y;
private float radious;
/**
* 圆圈的中心是不是满的
*/
private boolean isFill;
private Paint paint;
private int color;
/**
* 默认的空虚圆圈的边线宽是三
* @param x
* @param y
* @param radious
* @param color
*/
public Dot(double x, double y, float radious, int color) {
this.x = x;
this.y = y;
this.radious = radious;
this.color = color;
isFill=true;
paint=new Paint();
}
public double getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public float getRadious() {
return radious;
}
public void setRadious(float radious) {
this.radious = radious;
}
public int getColor() {
return color;
}
public void setColor(int color) {
color = color;
}
public void setLovation(float x,float y){
this.x=x;
this.y=y;
}
public void drawSelf(Canvas canvas){
if(isFill){
paint.setStyle(Paint.Style.FILL);
}else{
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(radious/6);
}
paint.setColor(color);
//设置抗锯齿
paint.setAntiAlias(true);
canvas.drawCircle((float)x,(float)y,radious,paint);
}
public boolean