Using GLSurfaceView class with android xml layouts

回眸只為那壹抹淺笑 提交于 2019-12-02 23:17:44
svdree

Just reference your own class (with full packagename) in the xml, the same way you reference android.opengl.GLSurfaceView. Make sure that your subclass implements the proper constructor, and passes the context & attributes to the parent:

public MyGLSurfaceView(Context context, AttributeSet attrs)
{
   super(context, attrs);

Then you can fetch it using findViewById:

MySurfaceView glSurfaceView = 
             (MySurfaceView)findViewById(R.id.surfaceviewclass);

That should do the trick.

If everything corect, like you write in the xml-layout, the full Path to the Glsurfaceview-class : (and classname)

it works only if the class, GLSurfaceView, written in a own File. in this file for shure, the construktors need to be written correctly.

i read about ,1 constructor for xml-refer, and one for comunication between classes. constructor for xml-refer, and one for comunication between classes, can be found, if written correcly, inside GLSurfaceView . GLSurfaceView, is where you set the Renderer, set it in the the xml constructor, must be the only way, it works fine. (shown in anwer 1)

xml-constructor:

public MyGLSurfaceView(Context context, AttributeSet attrs) { super(context, attrs); setEGLContextClientVersion(2);
renderer = new Renderer(context); setRenderer(renderer);

If you some of this peoples, who cant get SurfaceView work, in xml-layout ore, who buy this book from Apress - Beginning 3D- Game-Development. dont be angry ore hurt yourself. At page 44-45 it be written, in one file. Write GLSurfaceView, like in my answer, in own file. Renderer is own file, where: onSurfaceCreated, onSurfaceChanged, onDrawFrame..can be found And The MainActivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!