视频:善知堂Android http://www.verycd.com/topics/2915940/
第四集:多线程
讲多线程的技术点
第五集(上):动态效果
class GameView extends View { private Paint paint = null; public GameView(Context context) { super(context); paint = new Paint();// 画笔 paint.setColor(Color.RED); paint.setStrokeWidth(5);// 画笔粗 new MyThread().start(); } class MyThread extends Thread { @Override public void run() { for(int i=0;i<100;i++) { try { Thread.sleep(1); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } GameView.this.postInvalidate();// 重新绘制 } } } @Override protected void onDraw(final Canvas canvas) { super.onDraw(canvas); canvas.drawLine(0, 0, new Random().nextInt(500), new Random().nextInt(500), paint); } }
可以随机画一条线。