SurfaceView SurfaceHolder

今天介绍的内容是SurfaceView中常用到的SurfaceHolder,如图所示
SurfaceView SurfaceHolder
前面介绍APP通过如下接口拿到SurfaceHolder对象去改变Surface的size, color format, 也可以通过canvs提供的接口来绘制surface等

269      public SurfaceHolder getHolder() {
270          return mSurfaceHolder;
271      }

接口介绍

mSurfaceHolder 为surfaceview的成员变量,类型为SurfaceHolder
SurfaceHolder 为 接口,代码路径为:

/frameworks/base/core/java/android/view/SurfaceHolder.java

主要包含如下的 interface:

Interface Comment
boolean isCreating() 标识surface是否已创建
void addCallback(Callback callback) 添加回调,监听surface状态
void removeCallback(Callback callback) 移除回调,取消监听
void setFixedSize(int width, int height) 重新设置surface的宽度和高度
void setSizeFromLayout() 设置surface的宽度和高度与Layout相同
void setFormat(int format) 设置surface buffer的color format
void setKeepScreenOn(boolean screenOn) 保持screen on
Canvas lockCanvas() 获取canvas用于绘制surface, 软体绘制
Canvas lockCanvas(Rect inOutDirty) 获取canvas,指定dirty区域,软体绘制
Canvas lockHardwareCanvas() 获取canvas, 硬件绘制
void unlockCanvasAndPost(Canvas canvas) 释放canvas
Surface getSurface() 获取surface
Rect getSurfaceFrame() 获取surface region,(left:0, top:0, right:width, bottom:height)

酷客网相关文章:

赞(1)

评论 抢沙发

评论前必须登录!