简体   繁体   English

Android Studio Camera2预览画面无法添加UI

[英]Android Studio Camera2 preview screen cannot add UI

Android Studio Camera2 preview screen cannot add UI. Android Studio Camera2预览画面无法添加UI。 I wonder if I can add other UI to the camera preview screen?我想知道我是否可以在相机预览屏幕上添加其他 UI? (Title Bar, Button, Text, etc.) I tried to add the above UI elements in the XML settings, but still no response during execution. (标题栏、按钮、文本等)我尝试在XML设置中添加上述UI元素,但执行过程中仍然没有响应。

The following is my activity_main.xml code:以下是我的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>

The following is my fragment_camera.xml code:以下是我的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 >

Other codes can refer to: https://github.com/xGonZh10n/Camera2Preview其他代码可以参考: https://github.com/xGonZh10n/Camera2Preview

Is there any error?有什么错误吗? Can you show us error logs?你能告诉我们错误日志吗? Check your permission in Android manifest.在 Android 清单中检查您的权限。 Maybe you missing this line.也许你错过了这条线。

<uses-permission android:name="android.permission.CAMERA" />

I have a suggestion for you.我有一个建议给你。 Camera2API is easier than other custom libs to integrate. Camera2API 比其他自定义库更容易集成。 Reference: https://developer.android.com/guide/topics/media/camera参考: https://developer.android.com/guide/topics/media/camera

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM