views:

99

answers:

1

I'm using OpenGL to render a game view in my android application. The game is turn based and I wish to add some buttons to the interface. I'd prefer to use standard Android widgets, structured in an XML-generated layout (or, if I have to, a hardcoded layout) and put the OpenGL view in its own window as part of that layout.

So in regards to this, I have 3 questions:

1: Is such a thing possible? I've done a few half-hearted tries, but have had no luck so far.

2: Is such a thing advisable? Does it carry a significant performance penalty, for example, over using OpenGL-based homebrew widgetry?

3: Is it possible to pass particular arguments to instances created in XML layouts? For example, my current OpenGL view has three arguments in its constructor; is it somehow possible for me to invoke that particular constructor with particular parameters when it's part of a layout?

+1  A: 

Not only are these things possible, they are commonplace! The OpenGL SurfaceView is just another View in Android and you can layer anything you want over top of it. In the app that I am building we use OpenGL to render interesting backgrounds while layer the entire menu overtop of it. There are no more significant performance concerns that you would have with OpenGL by itself. You can use xml layouts or generate all of your ui elements programmatically or do some combination of the two. Even if you want to use xml to instantiate your ui you can get access to the elements and manipulate them based on state.

CaseyB
Allright, thanks. I've been unable to find any examples of this so far, but I'll look harder now that I know that it's not a dead end track.
Hnefi