首页 > 解决方案 > How to overlay TextView on JavaCameraView in android

问题描述

I want to overlay transparent TextView on JavaCameraView in Android like this picture. How can I do this? I tried to put TextView in JavaCameraView but it didn't work.

enter image description here

<org.opencv.android.JavaCameraView
    android:id="@+id/activity_java_surface_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

标签: android

解决方案


您应该使用 ConstraintLayout 或 RelativeLayout。在这些视图中,可以将视图放置在彼此之上。

尝试这个:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                                   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">

    <org.opencv.android.JavaCameraView
        android:id="@+id/activity_java_surface_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"/>

    <TextView
        android:id="@+id/text_overlay"
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:text="test text"
        android:background="#00000000"
        app:layout_constraintBottom_toBottomOf="@id/activity_java_surface_view"
        app:layout_constraintEnd_toEndOf="@id/activity_java_surface_view"
        app:layout_constraintStart_toStartOf="@id/activity_java_surface_view"
        />

推荐阅读