问题
I'm learning OpenGL on Android. I've written an app where the GlSurfaceView is declared in the layout XML (fragment...)
<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>
... and in its constructor the renderer is being set:
public M3View(Context context, AttributeSet attrs) {
super(context, attrs);
renderer = new M3Renderer(context);
setRenderer(renderer);
}
When the activity receives onResume/onPause it is properly calling the GlSurfaceView methods. But the renderer is never being started! Breakpoints in onSurfaceCreated() and other methods in the renderer are never being hit and nothing is rendered. How do I figure out what's happening here?
回答1:
(This answer comes from your other question : Trying to start renderer from GLSurfaceView declared in layout)
You didn't specify your LinearLayout orientation, so it is set to horizontal by default. This means your GLSurfaceView is outside of the screen (because you set your button width to fill_parent).
Just add the following attribute to your LinearLayout :
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
来源:https://stackoverflow.com/questions/8498877/glsurfaceview-renderer-not-being-called