2

我有一个MediaPlayer使用 aSurfaceView来显示视频。现在我想添加一个GlSurfaceViewMediaPlayerto视频上渲染一个立方体。我正在使用相对布局。而且我可以分开做这两项工作,但是我不能GlSurfaceViewSurfaceView. 它根本不会渲染我用于立方体的 OpenGL 代码。有人可以帮忙吗?

   _cube = new CubeGLView(this);
   _cube.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
   _cube.setId(10002);
   _cube.getHolder().setFormat(PixelFormat.TRANSLUCENT);
   _cube.getHolder().setFormat(PixelFormat.RGBA_8888);
   //_cube.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);

   _render = new GlRenderer(_cube.getContext());
   _cube.setRenderer(_render);
   _cube.setVisibility(View.GONE);

   RelativeLayout layout = new RelativeLayout(this);
   RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
   RelativeLayout.LayoutParams.MATCH_PARENT,
   RelativeLayout.LayoutParams.MATCH_PARENT);

   RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
   RelativeLayout.LayoutParams.WRAP_CONTENT,
   RelativeLayout.LayoutParams.WRAP_CONTENT);
   lp.addRule(RelativeLayout.CENTER_IN_PARENT);

   mPreview.setLayoutParams(lp);
   _cube.setLayoutParams(lp);

   layout.addView(_cube);
   layout.addView(mPreview);

   setContentView(layout, rlp);
4

1 回答 1

2

解决它: mPreview = new SurfaceView(this); mPreview.setId(10001);

    mPreview.setOnClickListener(this);
    mPreview.setClickable(true);

    holder = mPreview.getHolder();
    holder.addCallback(this);
    holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    extras = getIntent().getExtras();


    _cube = new CubeGLView(this);
    _cube.setEGLConfigChooser(8, 8, 8, 8, 16, 0);

    _cube.setId(10002);
    _cube.getHolder().setFormat(PixelFormat.TRANSLUCENT);
    _cube.getHolder().setFormat(PixelFormat.RGBA_8888);


    _render = new GlRenderer(_cube.getContext());
    _cube.setRenderer(_render);



    RelativeLayout layout = new RelativeLayout(this);
    RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);

    RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    lp.addRule(RelativeLayout.CENTER_IN_PARENT);

    mPreview.setLayoutParams(lp);

    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(100,10, 0,0);
    _cube.setLayoutParams(params);

    DataManager datamanager = DataManager.getInstance();

    if (!datamanager.isHasalreadyview()){
        Log.d(TAG, "onCreate icicle == null");
        layout.addView(_cube);
        layout.addView(mPreview);
        datamanager.setHasalreadyview(true);
    }else{
        Log.d(TAG, "onCreate icicle != null");
        layout.addView(mPreview);
        layout.addView(_cube);
    }


    setContentView(layout, rlp);
于 2012-06-04T12:37:49.820 回答