与Android XML布局使用GLSurfaceView类 [英] Using GLSurfaceView class with android xml layouts

查看:2492
本文介绍了与Android XML布局使用GLSurfaceView类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用Android的XML布局。我已经把glSurfaceView在一个框架布局结合使用具有像这样的线性布局...

I want to make use of the android xml layouts. I have put a glSurfaceView in a frame layout to use in conjunction with a linear layout like so...

<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>

然后我打电话给我的布局,像这​​样

I then call my layout like so

setContentView(R.layout.main);
    GLSurfaceView glSurfaceView = (GLSurfaceView)findViewById(R.id.surfaceviewclass);

在的onCreate();

in onCreate();

怎么能说我glSurfaceView,这样我可以利用XML的布局是这样的,并引用自己的GLSurfaceView类(下文为code,引用我自己GLSurfaceView类)...

How can I call my glSurfaceView so that I can make use of the xml layouts like this and also reference my own GLSurfaceView class (below is code that references my own GLSurfaceView class)...

glSurfaceView = new MyGLSurfaceView(this);
    setContentView(glSurfaceView);

反正是有把两者结合起来的?我想这样做,因为我已经得到的东西会在我的glSurfaceView类如文件加载和触摸事件的负载。而且,只有我只是想过实施这个新的布局

Is there anyway of combining these two? I want to do this cos I've got a load of stuff going on in my glSurfaceView class like file loading and touch events. And only I've just thought about implementing this new layout

推荐答案

只是引用自己的类(提供完整的软件包名)在XML中,您引用android.opengl.GLSurfaceView以同样的方式。请确保您的子类实现适当的构造,并通过上下文和放大器;属性父:

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);

然后就可以使用findViewById获取它:

Then you can fetch it using findViewById:

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

这是应该做的伎俩。

这篇关于与Android XML布局使用GLSurfaceView类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆