gpt4 book ai didi

android - 是否可以在同一屏幕上显示 Camera Preview 和 TextView?

转载 作者:太空宇宙 更新时间:2023-11-03 13:35:45 27 4
gpt4 key购买 nike

我想知道是否有某种方法可以让相机预览填充屏幕的一部分,并在底部有一个 TextView 框,我可以稍后在其中添加文本。我还没有任何代码,因为我的团队仍在评估这是否可行,然后再继续编写代码。

编辑 2:现在我终于可以在使用 android:gravity 后看到屏幕上的文字了。但是 TextView 总是显示在屏幕的顶部,有什么办法可以将它移到底部吗?

编辑 3:将 android:layout_height 更改为 fill_parent 而不是 wrap_content 修复了定位问题

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<SurfaceView android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"/>
<com.google.zxing.client.android.ViewfinderView
android:id="@+id/viewfinder_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/transparent"/>
........
........
<TextView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:text="Header text"/>

</FrameLayout>

最佳答案

是的,这是可能的。为此,您应该使用 FrameLayout。这是一个例子:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<SurfaceView android:id="@+id/preview_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_centerInParent="true"/>

<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top|center_horizontal"
android:text="Header text"/>

</FrameLayout>

关于android - 是否可以在同一屏幕上显示 Camera Preview 和 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7572189/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com