是否可以在相同的屏幕上显示Camera Preview和TextView?
我想知道是否有某种方法可以让相机预览填充屏幕的一部分,并且在底部有一个textview框供我稍后添加文本。 我还没有任何代码,因为在继续执行代码之前,我的团队仍在评估这是否可行。是否可以在相同的屏幕上显示Camera Preview和TextView?
编辑2:现在我终于能够在玩android:gravity之后看到屏幕上的文字。但是TextView总是显示在屏幕的顶部,有什么方法可以将它移动到底部?
编辑3:改变机器人: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>
是有可能是这样的:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<android.view.SurfaceView
android:id="@+id/surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<TextView
android:id = "@+id/txtview"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:text = "TextView"
android:padding = "7dp"
android:gravity = "bottom" />
</FrameLayout>
有没有什么办法可以将两个答案都设置为接受。我只能设置一个答案。 感谢您的帮助,我现在有点工作了,但我无法将textview的位置更改为底部..它始终显示在顶部。有小费吗? –
没关系,我认为你得到了你问的解决方案....干杯.... –
感谢您的回答,我应该提到的是,我发现了摄像头预览实际上是从斑马线的条码扫描器延长。我想减少相机预览尺寸,并在底部有一个Textview。我尝试添加TextView作为你们两个人的建议,但我无法看到任何区别。为了您的参考,我将附上zxing xml文件 –
它现在可以使用!但是有一个小问题,我编辑了我的帖子以包含我正在处理的代码。重力似乎不能正常工作:/我需要线性布局吗? –
您使用了'android:layout_height =“wrap_content”',而它应该是'fill_parent'来表示水平重力以使感觉/工作。 – inazaruk