我想利用android xml布局。我已经将glSurfaceView放在框架布局中,可以与线性布局结合使用,例如...
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<android.opengl.GLSurfaceView android:id="@+id/surfaceviewclass"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</FrameLayout>
<LinearLayout android:id="@+id/gamecontrolslayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="5"
android:background="@drawable/backdrop">
//some layout stuff
</LinearLayout>
<LinearLayout>
然后我这样称呼我的布局
setContentView(R.layout.main);
GLSurfaceView glSurfaceView = (GLSurfaceView)findViewById(R.id.surfaceviewclass);
在onCreate();中
我该如何调用我的glSurfaceView,以便我可以利用这样的xml布局,还可以引用我自己的GLSurfaceView类(下面的代码引用了我自己的GLSurfaceView类)...
glSurfaceView = new MyGLSurfaceView(this);
setContentView(glSurfaceView);
无论如何,将两者结合起来?我想这样做是因为我在glSurfaceView类中有很多东西在进行,例如文件加载和触摸事件。而且只有我刚刚考虑过实施这种新布局
只需在xml中引用您自己的类(具有完整的包名),就像引用android.opengl.GLSurfaceView一样。确保您的子类实现了正确的构造函数,并将上下文和属性传递给父类:
public MyGLSurfaceView(Context context, AttributeSet attrs)
{
super(context, attrs);
然后,您可以使用findViewById获取它:
MySurfaceView glSurfaceView =
(MySurfaceView)findViewById(R.id.surfaceviewclass);
这应该够了吧。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句