surfaceview和surfaceholde源码分析及其运用

1、SurfaceHolder
public interface SurfaceHolder

显示一个surface的抽象接口,使你可以控制surface的大小和格式, 以及在surface上编辑像素,和监视surace的改变。

这个接口通常通过SurfaceView类实现。

源码

	public interface SurfaceHolder {
		//.........
	    public interface Callback {
	        /**
	         * This is called immediately after the surface is first created.
	         * Implementations of this should start up whatever rendering code
	         * they desire.  Note that only one thread can ever draw into
	         * a {@link Surface}, so you should not draw into the Surface here
	         * if your normal rendering will be in another thread.
	         * 
	         * @param holder The SurfaceHolder whose surface is being created.
	         */
	        public void surfaceCreated(SurfaceHolder holder);

	        /**
	         * This is called immediately after any structural changes (format or
	         * size) have been made to the surface.  You should at this point update
	         * the imagery in the surface.  This method is always called at least
	         * once, after {@link #surfaceCreated}.
	         * 
	         * @param holder The SurfaceHolder whose surface has changed.
	         * @param format The new PixelFormat of the surface.
	         * @param width The new width of the surface.
	         * @param height The new height of the surface.
	         */
	        public void surfaceChanged(SurfaceHolder holder, int format, int width,
	                int height);

	        /**
	         * This is called immediately before a surface is being destroyed. After
	         * returning from this call, you should no longer try to access this
	         * surface.  If you have a rendering thread that directly accesses
	         * the surface, you must ensure that thread is no longer touching the 
	         * Surface before returning from this function.
	         * 
	         * @param holder The SurfaceHolder whose surface is being destroyed.
	         */
	        public void surfaceDestroyed(SurfaceHolder holder);
	    }
	    //.....................
	}

surface的控制器,用来操纵surface,处理它的Canvas上画的效果和动画,控制表面,大小,像素等。
几个需要注意的方法:
(1)abstract void addCallback(SurfaceHolder.Callback callback);
// SurfaceView当前的持有者一个回调对象。
(2)abstract Canv

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值