将GLSurfaceView类与android xml布局一起使用

杰克:

我想利用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类中有很多东西在进行,例如文件加载和触摸事件。而且只有我刚刚考虑过实施这种新布局

svdree:

只需在xml中引用您自己的类(具有完整的包名),就像引用android.opengl.GLSurfaceView一样。确保您的子类实现了正确的构造函数,并将上下文和属性传递给父类:

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

然后,您可以使用findViewById获取它:

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

这应该够了吧。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将滚动视图与自动布局Swift一起使用

XML布局中的Android GLSurfaceView

约束布局-将布局分组在一起

尝试将FOR XML Path与except一起使用

将Flask XML-RPC与HTTPAuth一起使用?

C ++:将相同的函数布局与不同的运算符和类方法一起使用

将邮政MVC与布局一起使用将标题解析为邮件正文

将ScreeManager与Kivy-按钮布局一起使用时出现问题

如何将 <img> 或 <canvas> 与“display: flex”布局一起使用

将布局锚点与 UIStackView 一起使用时出错

将折叠式工具栏与基于片段元素的布局一起使用

将Flexbox布局与angular-ui选项卡一起使用

如何将paintComponent 方法与布局管理器一起使用

将 XML 转换为 JSON,与 FasterXML 一起使用的 jaxb 类问题

需要帮助以获取自定义布局以与我的Android AlertDialog一起使用

将Android导航组件与片段内的单个活动,布局抽屉和工具栏一起使用

如何在Android中将以编程方式创建的水平滚动视图与XML创建的布局一起放置?

将布局放在一起 - 问题

如何将Android REGEX与Pattern和Matcher类一起使用?

setContentView()与GLSurfaceView一起使用时崩溃

故事板中的UIScrollView无法与iOS 8尺寸类和自动布局一起使用

将MEF与抽象基类一起使用

如何将c ++类与ctypes一起使用?

无法将Tuple类与本机查询一起使用

如何将ContextWrapper类与subscribeWith一起使用

将HashSet与用户类Employee一起使用

将instanceof与类Object一起使用

将Architect与Django Abstract Model类一起使用

NoSuchElementException将Iterator类与HashSet一起使用