GLSurfaceView 的onDrawFrame()频繁调用

可用GlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY)
GlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY)来控制是否持续渲染,
在特殊场合下灵活调用比在 activity的onPause()和onResume()中调用GLSurfaceview的onPause()、onResume()更有效率,
比如用glsurfaceview浏览全景图时,可在手势按下时设置模式为RENDERMODE_CONTINUOUSLY,在手指抬起或取消时设置模式为RENDERMODE_WHEN_DIRTY

public boolean onTouchEvent(MotionEvent e) {
        //隐藏中间的标记图

        if (mTapViewShow) {
            UiUtils.fadeViewOut(mCenterImage, new Runnable() {

                @Override
                public void run() {
                    mCenterImage.setVisibility(View.GONE);
                }
            });
            mTapViewShow = false;
        }
        if (mPanoramicMode) {
        float y = e.getY();
        float x = e.getX();
        switch (e.getAction()) {
        case MotionEvent.ACTION_MOVE:
            float dy = y - mPreviousY;
            float dx = x - mPreviousX;
            planeRender.yAngle += dx * 0.3f;
            planeRender.xAngle += dy * 0.3f;
            break;
        case MotionEvent.ACTION_DOWN:
            mReadingFeature.lockCurrentPageScroll();
            mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
            break;
        case MotionEvent.ACTION_UP:
            mReadingFeature.unLockCurrentPageScroll();
            mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
            break;
        case MotionEvent.ACTION_CANCEL:
            mReadingFeature.unLockCurrentPageScroll();
            mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
            break;
        }
        mPreviousY = y;
        mPreviousX = x;
        return true;
        } 
        return super.onTouchEvent(e);
    }

对于需要持续动态渲染的还是在生命周期中合适

你可能感兴趣的:(日常记录,OnDrawFram,RenderMode)