How can I use GLSurfaceView in a LinearLayout together with other Views, such as TextView or Button?

帅比萌擦擦* 提交于 2019-12-11 06:44:02

问题


I'm doing a small game on Android 2.3.3 and I want to use openGLES. My question is whether I can GLSurfaceView and TextView, Button in the same layout. My layout xml file is as the following

  <?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"
/>

When GameView extends GLSurfaceView there will be errors java.lang.NoSuchMethodException: GameView(Context,AttributeSet) but GameView extends GLSurfaceView will do.
If not, is there a way to put those widgets together?
Thx in advance


回答1:


When extending View or in this case GLSurfaceView you might need to place the correct constructor.

In your case you are missing this one:

public GameView(Context context, AttributeSet attrs)

You can check how it's done inside cocos2d-x with the Cocos2dxGLSurfaceView.



来源:https://stackoverflow.com/questions/8241975/how-can-i-use-glsurfaceview-in-a-linearlayout-together-with-other-views-such-as

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!