GLSurfaceView and other views in the same layout


Last Updated:

  1. raiderJerry

    raiderJerry New Member This Topic's Starter

    Joined:
    Aug 10, 2010
    Messages:
    2
    Likes Received:
    0
    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 (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="vertical" android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent">
    6.    
    7.     <!-- View Container -->
    8.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    9.         android:orientation="horizontal" android:layout_width="fill_parent"
    10.         android:layout_height="wrap_content" android:layout_gravity="top" >
    11.        
    12.         <android.opengl.GLSurfaceView android:id="@+id/glSurface"
    13.             android:layout_width="wrap_content" android:layout_height="wrap_content" />
    14.     </LinearLayout>
    15.  
    16.     <!-- Controls Container -->
    17.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    18.         android:orientation="horizontal" android:layout_width="wrap_content"
    19.         android:layout_height="wrap_content" android:layout_gravity="bottom">
    20.  
    21.         <Button android:id="@+id/leftSignalButton" android:text="@+string/leftSignalButtonLabel"
    22.             android:onClick="clickHandler" android:layout_width="wrap_content"
    23.             android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="left"/>
    24.  
    25.         <Button android:id="@+id/rightSignalButton" android:text="@+string/rightSignalButtonLabel"
    26.             android:onClick="clickHandler" android:layout_width="wrap_content"
    27.             android:layout_height="wrap_content" android:gravity="center" android:layout_gravity="right"/>
    28.  
    29.     </LinearLayout>
    30.  
    31. </LinearLayout>
    32.  
    Here is my activity code

    Code (Text):
    1.  
    2.      public void onCreate(Bundle savedInstanceState)
    3.     {
    4.         super.onCreate(savedInstanceState);
    5.  
    6.         setContentView(R.layout.main);
    7.  
    8.         this.surfaceView = (GLSurfaceView) this.findViewById(R.id.glSurface);
    9.         if (this.surfaceView != null)
    10.         {
    11.             this.surfaceView.setRenderer(new DrawSomethingRenderer(this));
    12.             this.surfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
    13.         }
    14.     }
    15.  
    Like I said, it draw the surfaceView just fine, but no buttons at the bottom.

    Thanks in advance
    raiderJerry
     

    Advertisement
  2. raiderJerry

    raiderJerry New Member This Topic's Starter

    Joined:
    Aug 10, 2010
    Messages:
    2
    Likes Received:
    0
    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 (Text):
    1.  
    2. <?xml version="1.0" encoding="utf-8"?>
    3. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    4.     android:orientation="vertical" android:layout_width="fill_parent"
    5.     android:layout_height="fill_parent">
    6.  
    7.     <!-- View Container -->
    8.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    9.         android:orientation="horizontal" android:layout_width="fill_parent"
    10.         android:layout_height="wrap_content" android:layout_gravity="top"
    11.         android:layout_weight=".9">
    12.         <android.opengl.GLSurfaceView android:id="@+id/glSurface"
    13.             android:layout_width="wrap_content" android:layout_height="wrap_content" />
    14.     </LinearLayout>
    15.  
    16.     <!-- Controls Container -->
    17.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    18.         android:orientation="horizontal" android:layout_width="fill_parent"
    19.         android:layout_height="wrap_content" android:layout_gravity="bottom"
    20.         android:layout_weight=".1">
    21.         <Button android:id="@+id/leftButton" android:text="@+string/leftButtonLabel"
    22.             android:onClick="clickHandler" android:layout_width="wrap_content"
    23.             android:layout_height="wrap_content" android:gravity="center"
    24.             android:layout_gravity="left" />
    25.         <Button android:id="@+id/rightButton" android:text="@+string/rightButtonLabel"
    26.             android:onClick="clickHandler" android:layout_width="wrap_content"
    27.             android:layout_height="wrap_content" android:gravity="center"
    28.             android:layout_gravity="right" />
    29.     </LinearLayout>
    30.  
    31. </LinearLayout>
    32.  
    Thanks for all the help!

    Raider
     
  3. shamshad

    shamshad New Member

    Joined:
    Oct 7, 2010
    Messages:
    1
    Likes Received:
    0
    hi all add button on text view in horizontal linear layout
     

Share This Page

Loading...