1. Are you ready for the Galaxy S20? Here is everything we know so far!

GLSurfaceView and other views in the same layout

Discussion in 'Android Development' started by raiderJerry, Aug 10, 2010.

  1. raiderJerry

    raiderJerry Lurker
    Thread Starter

    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
     


  2. raiderJerry

    raiderJerry Lurker
    Thread Starter

    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 Lurker

    hi all add button on text view in horizontal linear layout
     
Loading...
Similar Threads - GLSurfaceView views same
  1. bjourine stekarfield
    Replies:
    0
    Views:
    206
  2. andreaalvise
    Replies:
    17
    Views:
    570
  3. Rajkumar Wadi
    Replies:
    4
    Views:
    185
  4. Tito_Lortex
    Replies:
    0
    Views:
    530
  5. Funkyrick
    Replies:
    1
    Views:
    501
  6. ajaymehta32
    Replies:
    1
    Views:
    269
  7. Axelmorgana
    Replies:
    0
    Views:
    181
  8. Helpjason
    Replies:
    2
    Views:
    661
  9. rewathym
    Replies:
    1
    Views:
    897
  10. gutthatrat
    Replies:
    1
    Views:
    371

Share This Page

Loading...