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每次预览都会黑屏一下的问题。

相关推荐
液态不合群4 分钟前
【面试题】MySQL 中 count(*)、count(1) 和 count(字段名) 有什么区别?
android·数据库·mysql
中达瑞和-高光谱·多光谱1 小时前
中达瑞和VIX-N220推扫式高光谱相机:助力中医舌苔面诊迈向客观化、智能化新时代
数码相机
雪球Snowball2 小时前
【Android关键流程】资源加载
android
2501_915918412 小时前
常见 iOS 抓包工具的使用,从代理抓包、设备抓包到数据流抓包
android·ios·小程序·https·uni-app·iphone·webview
墨月白3 小时前
[QT]QProcess的相关使用
android·开发语言·qt
enbug4 小时前
编译安卓内核:以坚果R1、魔趣MK100(Android 10)系统为例
android·linux
、BeYourself4 小时前
应用专属文件与应用偏好设置(SharedPreferences)
android
2501_948120154 小时前
基于模糊数学的风险评估模型
android
MengFly_4 小时前
Compose 脚手架 Scaffold 完全指南
android·java·数据库
工业相机定制与开发5 小时前
云钥科技AI智能相机为图文印刷行业提供全流程检测解决方案
人工智能·数码相机