Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have Camera Preview and TextView on the same screen?

I was wondering if there is some way to have a camera preview fill a part of the screen, and at the bottom have a textview box into which I can add text later. I don't have any code yet because my team is still evaluating if this is possible at all before proceeding with the code.

Edit 2: Now I am finally able to see the text on the screen after playing around with android:gravity. But the TextView always shows up on the top of the screen, is there some way to move it to the bottom?

Edit 3: Changing android:layout_height to fill_parent instead of wrap_content fixed the positioning issue

<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>
like image 616
Rahul Popuri Avatar asked Oct 21 '25 01:10

Rahul Popuri


1 Answers

Yes, this is possible. You should use FrameLayout for this. Here is an example:

<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>
like image 61
inazaruk Avatar answered Oct 23 '25 15:10

inazaruk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!