{
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
int color;
int x=0;
int y=0;
int r=0;
int n=0;
int needUpdate = 0;
DrawCircle circle = null;
public DrawCircle(Context con, AttributeSet attr)
{
super(con,attr);
circle = this;
new Thread(new Runnable()
{
@Override
public void run()
{
while(n < 10)
{
Thread.sleep(500);
needUpdate = 1;
circle.postInvalidate();
n ++;
}
}
}).start();
}
@Override
protected void onDraw(Canvas c)
{
super.onDraw(c);
try
{
if (needUpdate == 1)
{
needUpdate = 0;
gen();
p.setColor(color);
p.setStyle(Paint.Style.FILL);
c.drawCircle(x, y, r, p);
}
}
catch (InterruptedException e)
{
e.printStackTrace();
}
}
public void gen()
{
color = Color.rgb(rand(0,255),rand(0,255),rand(0,255));
x=rand(0,1200);
y=rand(0,1200);
r=rand(50,150);
}
public int rand(int a, int b)
{
return((int)((b-a+1)*Math.random() + a));
}
}
手打的 不知道有沒有錯。妳看壹下