解决方案
1、使用动态添加的方式添加surfaceView
在xml文件中添加FrameLayout
- <FrameLayout
- android:id="@+id/colorsurface"
- android:layout_width="match_parent"
- android:layout_height="match_parent" />
- surfaceView = new SurfaceView(this);
- screenBinding.colorsurface.addView(surfaceView);
- surfaceView.setZOrderMediaOverlay(true);
- surfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);
即可解决surfaceview每次预览都会黑屏一下的问题。