How to use GLSurfaceView in LinearLayout together with other views like TextView or Button?

I am making a small game on Android 2.3.3 and I want to use openGLES. My question is: can I GLSurfaceView and TextView , Button in the same layout. My layout xml file is as follows

<?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 will be errors java.lang.NoSuchMethodException: GameView(Context,AttributeSet) , but GameView extends GLSurfaceView will do.
If not, is there a way to combine these widgets?
thanks in advance

+1
source share
1 answer

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

In your case, you are missing this:

 public GameView(Context context, AttributeSet attrs) 

You can check how this is done inside cocos2d-x with Cocos2dxGLSurfaceView .

+4
source

Source: https://habr.com/ru/post/1388687/


All Articles