一、activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<SurfaceView
android:id="@+id/surface_view"
android:layout_width="353dp"
android:layout_height="621dp"
android:layout_marginStart="24dp"
android:layout_marginTop=&
本文详细介绍了如何在Android应用中打开并预览摄像头。通过在activity_main.xml中设置SurfaceView,然后在MainActivity.java中获取权限,设置SurfaceHolder,并在回调中创建并启动相机预览。代码示例包括了请求相机权限、设置SurfaceView尺寸以及相机预览的生命周期管理。
订阅专栏 解锁全文

590

被折叠的 条评论
为什么被折叠?



