Как я могу использовать GLSurfaceView в LinearLayout вместе с другими представлениями, такими как TextView или Button? - PullRequest
1 голос
/ 23 ноября 2011

Я делаю небольшую игру на 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.
Если нет, есть лиспособ соединить эти виджеты?
Спасибо заранее

1 Ответ

4 голосов
/ 23 ноября 2011

При расширении View или в этом случае GLSurfaceView может потребоваться разместить правильный конструктор.

В вашем случае вам не хватает этого:

public GameView(Context context, AttributeSet attrs)

Вы можете проверить, как это делается внутри cocos2d-x с помощью Cocos2dxGLSurfaceView .

...