java - Android Studio Camera2预览画面无法添加UI
问题描述
Android Studio Camera2 预览画面无法添加 UI。我想知道我是否可以在相机预览屏幕上添加其他 UI?(标题栏、按钮、文本等) 我尝试在 XML 设置中添加上述 UI 元素,但在执行过程中仍然没有响应。
以下是我的activity_main.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="657dp"
android:background="#000"
android:orientation="vertical"
tools:context=".MainActivity">
</FrameLayout>
</RelativeLayout>
以下是我的fragment_camera.xml代码:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp"
android:orientation="vertical"
tools:context=".CameraFragment">
<com.lightweh.camera2preview.AutoFitTextureView
android:id="@+id/textureView"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</FrameLayout >
解决方案
有什么错误吗?你能告诉我们错误日志吗?检查您在 Android 清单中的权限。也许你错过了这条线。
<uses-permission android:name="android.permission.CAMERA" />
我有一个建议给你。Camera2API 比其他自定义库更容易集成。参考:https ://developer.android.com/guide/topics/media/camera
推荐阅读
- javascript - 获得一个通过发出的下一个值解决的承诺
- laravel - 单选按钮未在 laravel Dusk 中选择
- asp.net - 多选复选框列表的级联
- ios - 如何从 App Store Connect 中删除自动创建的 macOS 应用程序
- php - PHP chrome-php / 无头铬-php
- winforms - Winforms Datagridview MultiSelect 选项未按预期工作
- javascript - 在 HTML 中自动添加或删除类
- sql - 替换不在 SQL 中做我需要的事情
- ios - 如何在无需用户注册的情况下将数据永久存储在服务器上
- java - 使用 Java 8 对 LocalDateTime 对象进行分组