Question

I need to have a GLSurfaceView over a Surface view. GLSurface view will have a Renderer and SurfaceView will be camera view.

Following is my layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

 <RelativeLayout
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/title_bar" >

    <Button
        android:id="@+id/BTN_HOME_DEVICES"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:background="@drawable/btn_home"
        android:text="@string/home_button"
        android:textAppearance="?android:attr/textAppearanceMediumInverse"
        android:textColor="@color/white" />

     <TextView
        android:id="@+id/BANNER_HELP"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/BTN_HOME_HELP"
        android:layout_alignBottom="@+id/BTN_HOME_HELP"
        android:layout_centerHorizontal="true"
        android:layout_centerInParent="true"
        android:text="@string/auto_text"
        android:textColor="@color/white"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textSize="20sp" />

</RelativeLayout>

   <RelativeLayout
       android:id="@+id/surface_layout"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:layout_alignParentRight="true"
       android:focusable="true" >

          <SurfaceView
              android:id="@+id/cameraPreview"
              android:layout_marginTop="120px"
              android:layout_width="fill_parent"
              android:layout_height="500dp" />

          <GLSurfaceView
              android:id="@+id/glView"
              android:layout_marginTop="120px"
              android:layout_width="fill_parent"
              android:layout_height="500dp" />



  </RelativeLayout>

   <LinearLayout
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:layout_alignParentBottom="true"
               android:orientation="horizontal"
                >

               <Button
                   android:id="@+id/stopButton"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_weight="0.20"
                   android:text="AR Call Stop" />

               <Button
                   android:id="@+id/startButton"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_weight="0.20"
                   android:text="AR Call Start" />
           </LinearLayout>
 </RelativeLayout>

And in my activity i'm getting the glsurface view like below

    GLSurfaceView glView = (GLSurfaceView) findViewById(R.id.glView);
    glView.setEGLConfigChooser( 8, 8, 8, 8, 16, 0 );
    glView.getHolder().setFormat( PixelFormat.TRANSLUCENT );

    glView.setRenderer( new GLClearRenderer() );

    setContentView(R.layout.auto_layout);

Here my glView is coming as null. how to achieve this behavior in a correct way?

Was it helpful?

Solution

I have solved the above problem by ignoring the xml logic completely and dynamically adding elements through addview.

So i was able to achieve what ever i wanted.

glView = new GLSurfaceView(this);
glView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
glView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
glView.setRenderer(new GLClearRenderer());

cameraPreview = new SurfaceView(this);
addContentView(cameraPreview, new   LayoutParams(cameraPreview.getLayoutParams().WRAP_CONTENT,
                            cameraPreview.getLayoutParams().WRAP_CONTENT));

addContentView(glView,new LayoutParams(cameraPreview.getLayoutParams().WRAP_CONTENT,
                    cameraPreview.getLayoutParams().WRAP_CONTENT));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top