public CustomView(Context context, AttributeSet attrs) { |
super(context, attrs); |
TypedArray typedArray=context.obtainStyledAttributes(attrs,R.styleable.customColor); |
/*firstColor=typedArray.getColor(R.styleable.customColor_firstColor, Color.parseColor("#00ff00")); |
secondColor=typedArray.getColor(R.styleable.customColor_secondColor,Color.parseColor("#ff0000")); |
circleWidth=(int)typedArray.getDimension(R.styleable.customColor_circleWidth,10);*/ |
typedArray.recycle(); |
} |
protected void onDraw(Canvas canvas) { |
super.onDraw(canvas); |
paint.setAntiAlias( true ); |
paint.setStyle(Paint.Style.STROKE); |
paint.setStrokeWidth(circleWidth); |
if (flag){ |
paint.setColor(firstColor); |
canvas.drawCircle(getWidth()/2,getHeight()/2,100,paint); |
paint.setColor(secondColor); |
canvas.drawArc( new RectF(getWidth()/2-100,getHeight()/2-100,getWidth()/2+100,getHeight()/2+100),-90,progress, false ,paint); |
} else { |
paint.setColor(secondColor); |
canvas.drawCircle(getWidth()/2,getHeight()/2,100,paint); |
paint.setColor(firstColor); |
canvas.drawArc( new RectF(getWidth()/2-100,getHeight()/2-100,getWidth()/2+100,getHeight()/2+100),-90,progress, false ,paint); |
} |
/*if(thread==null){ |
thread=new MyThread(); |
thread.start(); |
}*/ |
} |
class MyThread extends Thread{ |
@Override |
public void run() { |
super.run(); |
while ( true ){ |
progress+=3; |
if (progress==360){ |
progress=0; |
if (flag){ |
flag= false ; |
} else { |
flag= true ; |
} |
} |
postInvalidate(); |
try { |
Thread.sleep(50); |
} catch (InterruptedException e) { |
e.printStackTrace(); |
} |
} |
} |
} |
中级程序员
by: 老四和老三的老二都老大了 发表于:2017-03-14 19:40:09 顶(0) | 踩(0) 回复
这B装的可以
回复评论