您的位置:首页 > 移动开发 > Android开发

android surfaceView与view使用小结

2012-04-14 17:33 274 查看
两种方法都是实现画一个慢慢变大的圆, 自定义的view要sleep一下才能看到效果 . surfaceView不用. 可能与其两级缓存有关.
_____________________________________最美分割线_________________________________________
使用它主要就是
SurfaceHolder sh = this.getHolder();--->1.得到SurfaceHolder
Canvas canvas = sh.lockCanvas();---->2. 锁定画布
Paint paint = new Paint();
paint.setColor(Color.RED); ----->3. 在画布上干事
canvas.drawCircle(100, 100, radius, paint);
sh.unlockCanvasAndPost(canvas); ----->4. 解除锁定

下面图片为全部代码.



_____________________________________最美分割线__________________________________________

view主要干活的是onDraw()方法.这个不用手动调(不像surfaceview还得还一个surfaceHolder.addCallback()方法)

其实surfaceview里的surfaceHolder.addCallback()方法是不断的调用Draw()方法. 这个方法文档的解释:Manually render this view (and all of its children) to the given Canvas. The view must have already done a full layout before this function is called. When implementing a view, implement
onDraw(android.graphics.Canvas)
instead of overriding this method. If you do need to override this method, call the superclass version.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: