2011-12-14 107 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">