Reputation: 4821
I rented a coder to develop an Android based OpenGL application for my company. The app does some pretty complex stuff and renders a 3d tube based on coordinates passed through an intent (from my other application). I need to add a button to his OpenGL app in order to exit the app and return to my original one. I've only touched on Java and have no idea how to add elements when a layout isn't involved. I don't want the button to be OpenGL based as I really don't know anything about OpenGL, so I'd rather have an Android element sitting on top of the activity.
This is how his create routine looks. (The intent that launches the app passes data. In order to compile I had to comment out that code and just make up the data).
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent = getIntent();
//String data = intent.getStringExtra("data");
//double radius = Double.parseDouble(intent.getStringExtra("radius"));
//double width = Double.parseDouble(intent.getStringExtra("width"));
String data = "254,0,90,2,254,0,90,2";
double radius = 20;
double width = 10;
openGLTube3D = new OpenGLTube3D(this, data, radius, radius, width);
setContentView(openGLTube3D);
}
He uses setContentView()
with his OpenGL class instead of an XML file, so I have no idea where to add the button.
Can anyone help?
Upvotes: 0
Views: 3777
Reputation: 35943
If OpenGLTube3D is a view, then I would recommend:
Create an XML file like you typically would, with a framelayout as the root, but leave the opengl view out. This should contain whatever buttons or widgets that you want to appaer on top of OpenGL view.
You'll want something like this (forgive any syntax errors below, I'm writing this from memory):
<FrameLayout
android:id="@+id/myframelayout>
<Button
android:...
android:...
android:... />
</FrameLayout>
Then, in onCreate, you want to set layout.xml as the content view, and then you want to insert the OpenGL view into the framelayout as the first index (so it will appear beneath the button)
Pseudocode:
openGLTube3D = new OpenGLTube3D(this, data, radius, radius, width);
FrameLayout frame = (FrameLayout)findViewById(R.id.myframelayout);
frame.addView(openGLTube3D, 0);
I believe this should place the OpenGL view below all of the other elements defined in your framelayout.
Upvotes: 4