Java Question [SOLVED} Add ImageView to xml layout

Johan Schoeman

Expert
Licensed User
Longtime User
I have a XML layout that looks as follows:

B4X:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

    <com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay
            android:id="@+id/graphicOverlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview>
   

</LinearLayout>

I need to add an imageview so that it is at the bottom centre of the UI once the camera preview started. I have tried this:

B4X:
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">

    <com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay
            android:id="@+id/graphicOverlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview>
   
   
    <LinearLayout
        android:id="@+id/buttonsLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        android:weightSum="4"
        android:layout_marginBottom="20dp">
       
        <ImageView
            android:id="@+id/button_picture"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/takepicturebutton"
            android:layout_weight="2"
            android:layout_gravity="left"/>           
    </LinearLayout>   

</LinearLayout>

The B4A program compiles and the app starts (i.e the preview is alive) but no sign of my imageview. I have updated the R.java file to allow for the id of the imageview and have declared and added code for the imageview in the java activity.

Any pointers will be much appreciated (I am a bit lost when it comes to xml layouts)....
 

Johan Schoeman

Expert
Licensed User
Longtime User
Solved it with this:
B4X:
<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/topLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:keepScreenOn="true">
   
    <com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview
        android:id="@+id/preview"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
   
        <com.google.android.gms.samples.vision.ocrreader.ui.camera.GraphicOverlay
            android:id="@+id/graphicOverlay"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </com.google.android.gms.samples.vision.ocrreader.ui.camera.CameraSourcePreview>
   
            <ImageView
                android:id="@+id/button_picture"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|center"/>
               
</FrameLayout>
 
Top