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