• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps GLSurfaceView and other views in the same layout

Hi all,

I am trying to display a GLSurfaceView at the top of the screen with a separate layout containing buttons at the bottom. Seems simple enough, in fact I can get it to work with the button layout at the top and the GLSurfaceView layout at the bottom. But when I put the GLSurfaceView at the top, the button layout just doesn't show up.


Here is my main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    
    <!-- View Container -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_gravity="top" >
        
        <android.opengl.GLSurfaceView android:id="@+id/glSurface"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>

    <!-- Controls Container -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:layout_gravity="bottom">

        <Button android:id="@+id/leftSignalButton" android:text="@+string/leftSignalButtonLabel"
            android:onClick="clickHandler" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="left"/>

        <Button android:id="@+id/rightSignalButton" android:text="@+string/rightSignalButtonLabel"
            android:onClick="clickHandler" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="right"/>

    </LinearLayout>

</LinearLayout>
Here is my activity code

Code:
     public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        this.surfaceView = (GLSurfaceView) this.findViewById(R.id.glSurface);
        if (this.surfaceView != null)
        {
            this.surfaceView.setRenderer(new DrawSomethingRenderer(this));
            this.surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
        }
    }
Like I said, it draw the surfaceView just fine, but no buttons at the bottom.

Thanks in advance
raiderJerry
 
It is working now. I added an android:weight to each second level layout components and my buttons are now appearing at the bottom of the screen as expected.

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

    <!-- View Container -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_gravity="top"
        android:layout_weight=".9">
        <android.opengl.GLSurfaceView android:id="@+id/glSurface"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>

    <!-- Controls Container -->
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="horizontal" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:layout_gravity="bottom"
        android:layout_weight=".1">
        <Button android:id="@+id/leftButton" android:text="@+string/leftButtonLabel"
            android:onClick="clickHandler" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:gravity="center"
            android:layout_gravity="left" />
        <Button android:id="@+id/rightButton" android:text="@+string/rightButtonLabel"
            android:onClick="clickHandler" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:gravity="center"
            android:layout_gravity="right" />
    </LinearLayout>

</LinearLayout>
Thanks for all the help!

Raider
 
Back
Top Bottom