如何在LinearLayout中将GLSurfaceView与其他视图一起使用,例如TextView或Button?

时间:2011-11-23 12:13:09

标签: android android-layout opengl-es-2.0

我在Android 2.3.3上做了一个小游戏,我想使用openGLES。我的问题是我是否可以在同一版面中 GLSurfaceView TextView 按钮。我的布局xml文件如下所示

  <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" 
android:gravity="center_horizontal" >

<com.ecnu.sei.manuzhang.nim.GameView
    android:id="@+id/game_view"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_margin="20dip"
    android:layout_weight="1"
 />

<TextView
    android:id="@+id/info_turn"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal"
    android:layout_marginBottom="10dip"
 />

<Button
    android:id="@+id/next_turn"
    android:text="@string/button_text"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dip"
    android:layout_marginRight="20dip"
/>

GameView extends GLSurfaceView出现错误java.lang.NoSuchMethodException: GameView(Context,AttributeSet)GameView extends GLSurfaceView会出错时    如果没有,有没有办法将这些小部件放在一起?
  Thx提前

1 个答案:

答案 0 :(得分:4)

扩展View或在这种情况下GLSurfaceView时,您可能需要放置正确的构造函数。

在你的情况下,你错过了这个:

public GameView(Context context, AttributeSet attrs)

您可以使用cocos2d-x检查Cocos2dxGLSurfaceView内部的完成情况。