Graphics Programs Reference
In-Depth Information
The addContentView method is also a public method of the an-
droid.app.Activity class. Unlike the setContentView method, the ad-
dContentView method requires an extra argument to obtain the view's layout in-
formation.
Using the addContentView method, we add an additional content view to the
activity. In an activity, if the argument passed to the setContentView method is
an OpenGL surface and the first argument passed to the addContentView meth-
od is a layout widget, the OpenGL surface is laid out below the layout widget ( Figure
2-11 ) . To get a better understanding, let's create a new application:
1. Click the wizard to create a new Android project.
2. Set the application and project name as “ADDCONTENTVIEW.”
3. Uncheck the “Create custom launcher icon” option and click “Next.”
4. For “Create Activity,” select BlankActivity and click “Next.”
5. Set the “Activity Name” and “Layout Name” as “Main” and “main,” re-
spectively.
6. Click “Finish.”
7. Copy the files GLES20Renderer.java and Main.java from GL
SURFACE application into the package for ADDCONTENTVIEW ap-
plication (confirm overwriting of Main.java ).
setContentView(_surfaceView); in Main.java ( ADDCONTENTVIEW
application) sets an OpenGL surface as the activity's content view. Now, we add a
layout widget (with button-views) as an additional content view ( Listing 2-5 ) .
Listing
2-5. ADDCONTENTVIEW/src/com/apress/android/addcontentview/
Main.java
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setPadding(0, 200, 0, 0);
1. After line 16 (the line with the call to the setContentView method)
in Main.java , add the lines of code from Listing 2-5 to create a Lin-
earLayout layout with vertical orientation and top-padding of 200
 
 
 
Search WWH ::




Custom Search