android - 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.
<org.opencv.android.JavaCameraView
android:id="@+id/activity_java_surface_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
解决方案
您应该使用 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"
/>
推荐阅读
- java - 在 Android Java 中键入时自动为 Edittext 中的 Hashtags 着色
- spring - 保存功能上的 EntityNotFoundException
- mysql - 从没有唯一列的重复行中获取第一行
- r - 如何在 R 中 ggplot2 的条形图中绘制多个变量(即类别)
- wordpress - 自定义 WooCommerce 网关 - 运行本地 JS 功能
- postgresql - 使用 PetaPoco 从 PostgreSQL 返回记录 ID
- python - NameError:名称“列表”未定义
- javascript - 在与应用程序一起打包的本地页面上启用 Electron 中的 nodeIntegration 是否安全?
- date - 如何在 Google 表格中按日期过滤?
- typescript - 如何在 ES6 或 Typescript 中使用 VueJS