Android SurfaceView预览相机黑屏问题解决方案

解决方案

1、使用动态添加的方式添加surfaceView

在xml文件中添加FrameLayout

<FrameLayout
    android:id="@+id/colorsurface"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /> 

2.创建SurfaceView并添加到FrameLayout上

surfaceView = new SurfaceView(this);
screenBinding.colorsurface.addView(surfaceView);

3.最后设置surfaceview两个属性

surfaceView.setZOrderMediaOverlay(true);
surfaceView.getHolder().setFormat(PixelFormat.TRANSPARENT);

即可解决surfaceview每次预览都会黑屏一下的问题。

相关推荐
与衫1 小时前
掌握嵌套子查询:复杂 SQL 中 * 列的准确表列关系
android·javascript·sql
摇曳的树3 小时前
【3D目标检测】激光雷达和相机联合标定(二)——MATLAB联合标定工具使用
数码相机·目标检测·3d
500了7 小时前
Kotlin基本知识
android·开发语言·kotlin
人工智能的苟富贵8 小时前
Android Debug Bridge(ADB)完全指南
android·adb
小雨cc5566ru13 小时前
uniapp+Android面向网络学习的时间管理工具软件 微信小程序
android·微信小程序·uni-app
bianshaopeng14 小时前
android 原生加载pdf
android·pdf
hhzz14 小时前
Linux Shell编程快速入门以及案例(Linux一键批量启动、停止、重启Jar包Shell脚本)
android·linux·jar
火红的小辣椒15 小时前
XSS基础
android·web安全
勿问东西17 小时前
【Android】设备操作
android
五味香17 小时前
C++学习,信号处理
android·c语言·开发语言·c++·学习·算法·信号处理