當前位置:編程學習大全網 - 源碼下載 - 小白請求android編程大佬幫忙,怎麽樣才能慢慢壹個接壹個顯示10個圓?

小白請求android編程大佬幫忙,怎麽樣才能慢慢壹個接壹個顯示10個圓?

public class DrawCircle extends View

{

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));

}

}

手打的 不知道有沒有錯。妳看壹下

  • 上一篇:tp3怎麽集成gatewayworker
  • 下一篇:給我發壹個C#版的網絡通信源代碼可以嗎?
  • copyright 2024編程學習大全網