2011-12-14 110 views
0

我学习的OpenGL Android上。我已经写在GlSurfaceView在布局XML声明的应用程序(片段...)GlSurfaceView渲染器不会被调用

<FrameLayout 
    android:id="@+id/framelay" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <com.nelsondev.myha3ogl.M3View 
    android:id="@+id/m3SurfView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"/> 
    </FrameLayout> 

...并在其构造的渲染器设置:

public M3View(Context context, AttributeSet attrs) { 
     super(context, attrs); 
     renderer = new M3Renderer(context); 
     setRenderer(renderer); 
    } 

当活动收到onResume/onPause它正确调用GlSurfaceView方法。 但是渲染器从未开始!在断点onSurfaceCreated()和渲染等方法永远不会被击中,并没有什么渲染。我怎么知道这里发生了什么?

+0

其实,我只是检查,我想我的回答你刚才的问题是错误的,实际上,启动()被调用的GLSurfaceView时首先布局(即当你调用`的setContentView(framelay)`或`的setContentView(R.layout.graphics)`与GLSurfaceView为/ framelay的孩子在文件graphics.xml),而不是当'setRenderer`被称为 – 2011-12-14 14:01:18

回答

3

(这个答案来自于您的其他问题:Trying to start renderer from GLSurfaceView declared in layout

你没有指定的LinearLayout的方向,因此它被默认设置为horizontal。这意味着您的GLSurfaceView在屏幕之外(因为您将按钮宽度设置为fill_parent)。

只需将以下属性添加到您的LinearLayout:

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent">