子类化SurfaceView并重写onDraw()以更改SurfaceView参数以生成所需大小的预览
作者:互联网
我已经将SurfaceView子类化,并在Activity的onCreate中实例化了它.预览已生成,但控件从未输入onDraw(),该值在SurfaceView的子类中被覆盖.这是为什么?
class ActivityClass extends Activity{
onCreate(){
mPreview = new Preview(this);
setContentView(mPreview);
}
public void startPreview(){
rec = new MediaRecorder();
rec.setVideoSource();.......
rec.setPreviewDisplay(mPreview.getSurfaceHolder.getSurface());
}
}
class Preview extends SurfaceView implements SurfaceHolder.Callback{
SurfaceHolder mHolder;
public Preview(Context context){
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
bringToFront();//this is not
invalidate();//making a difference
}
SurfaceHolder getSurfaceHolder(){
return mHolder;
}
//Surface callback methods implemented here
}
在Surface上绘制预览之前,是否应将控件提供给onDraw回调(如果已实现)?
因为onDraw回调对Android框架说’您不绘制视图.自实施以来,我将对其进行绘制.我对吗?
那么,为什么控件无法输入onDraw()?请帮忙.
解决方法:
您只需要添加
setWillNotDraw(false)
给构造函数.
它完成了..
标签:surfaceview,ondraw,view,android,preview 来源: https://codeday.me/bug/20191209/2097577.html