大佬教程收集整理的这篇文章主要介绍了android – onSurfaceCreated()在每次方向更改时调用,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
public class GL20Renderer implements GLSurfaceView.Renderer { private static GL20Renderer mInstance = new GL20Renderer(); private GL20Renderer() {} public static GL20Renderer geTinstance() { return mInstance; } @Override public void onDrawFrame(GL10 gl) { Log.e("App","onDrawFrame()"); } @Override public void onSurfaceChanged(GL10 gl,int width,int height) { Log.e("App","onSurfaceChanged()"); } @Override public void onSurfaceCreated(GL10 gl,EGLConfig config) { Log.e("App","onSurfaceCreated()"); } }
此类在MainActivity中实现:
public class MainActivity extends Activity { private GLSurfaceView mGLView; @Override protected void onCreate(Bundle savedInstanceStatE) { super.onCreate(savedInstanceStatE); requestWindowFeature(Window.FEATURE_NO_titlE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN); // Create a GLSurfaceView instance and set it as the ContentView for this Activity mGLView = new GL20SurfaceView(this); setContentView(mGLView); } @Override protected void onPause() { super.onPause(); mGLView.onPause(); } @Override protected void onResume() { super.onResume(); mGLView.onResume(); } }
GL20SurfaceView是:
public class GL20SurfaceView extends GLSurfaceView { public GL20SurfaceView(Context context) { super(context); // Create an OpenGL ES 2.0 context. setEGLContextClientVersion(2); // Set the Renderer for drawing on the GLSurfaceView setRenderer(GL20Renderer.geTinstance()); } }
你可以看到非常简单.
当我现在启动App时,正确调用onSurfaceCreated()方法,然后调用onSurfaceChanged().
现在的问题是:每当设备方向改变时,我会再次调用onSurfaceCreated(),然后调用onSurfaceChanged().
根据我的理解,只要需要创建新表面,就会调用onSurfaceCreated()方法.我的问题是:每当我改变设备方向时,为什么会这样做?为了调整视口,仅触发onSurfaceChanged()调用是不是足够了?
请注意,更改方向时,我不会让设备进入睡眠状态.
<activity android:name=".MainActivity" android:configChanges="keyboardHidden|orientation|screenSize" />
以上是大佬教程为你收集整理的android – onSurfaceCreated()在每次方向更改时调用全部内容,希望文章能够帮你解决android – onSurfaceCreated()在每次方向更改时调用所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。