Android glSurfaceView with overlay using XML/Java

白昼怎懂夜的黑 提交于 2019-12-01 04:57:49

Okay, so the proper way of doing this is to have a constructor in the B class which takes in:

B(Context context, AttributeSet attrs)
{
  super(context, attrs);
}

And in the XML layout, use this:

<com.bla.bla.B
        android:id="@+id/glsurfaceview"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

The thing that was missing in my code was the constructor signature.

An alternate way to solve this, is to leave your views attached to Activity A. So instead of using setContentView(B object) you use setContentView(A object) and inside your "A XML" file, is the GLsurfaceView view:

<android.opengl.GLSurfaceView android:id="@+id/glsurfaceview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

You can then refer to your B object in the Activity A, because it was inflated when you setContentView to A, instead of B:

GLSurfaceView glSurfaceView = (GLSurfaceView) findViewById(R.id.glsurfaceview);


glSurfaceView.setRenderer();  //no longer have to pass the object

I'm honestly not sure how to get it to work exactly the way you want, but in your case I'm not sure it ultimately makes a difference. Then again, I'm still a novice too. I'd be interested to learn how to do this in an alternate fashion as I asked a similar question just today.

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