1
我对OpenGL相当陌生,我的问题是当我做SetContentView("R.layout.main")
没有任何反应,但是当我做SetContentView("mGLView")
时,游戏显示正常。我的main.xml文件包含一个表面视图,因此我会认为它会显示,因为main.xml有一个表面视图。OpenGL ES 2:当SetContentView设置为XML文件时,GLSurface视图显示黑色屏幕
我怀疑一种方法来解决这个问题,将与addview或findviewbyid完成,但我的意思是失败。
培训相关MainActivity代码:
public class OpenGLES20Activity extends Activity {
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new MyGLSurfaceView(this);
setContentView(R.layout.main);
的main.xml代码:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout android:id="@+id/linearLayout1" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<SurfaceView
android:id="@+id/SurfaceView"
android:layout_width="500dp"
android:layout_height="478dp">
</SurfaceView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Timer"
android:id="@+id/Timer"/>
</RelativeLayout>
</FrameLayout>
任何帮助表示赞赏。
我所做的变化在我的代码,现在我有以下的错误错误:(31,19)错误:类MyGLSurfaceView中的构造函数MyGLSurfaceView无法应用于给定的类型; 必需:上下文,AttributeSet 找到:没有参数 原因:实际和正式参数列表长度不同 – DarkEnergy
您的构造函数需要为'MyGLSurfaceView(Context context,AttributeSet attrs)''就像我已链接到您的文档中所示。 – MarGenDo
我的构造函数被设置为,我仍然得到错误。 如果这有助于我的IDE已经表明这是一个问题:mGLView = new MyGLSurfaceView(this); – DarkEnergy