开发者

OpenGL and layouts

开发者 https://www.devze.com 2022-12-31 05:42 出处:网络
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

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 开发者_如何学CXML 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?


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.


I had this same question, here's an example:

http://android-er.blogspot.com/2010/05/another-exercise-of-surfaceview-in.html

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号