我的相机视图与GLSurfaceView重叠...但我希望它被GLSurfaceView覆盖

时间:2011-10-05 07:32:02

标签: android android-layout camera glsurfaceview

我有一个增强现实应用程序,它显示了摄像机视图和带有多边形的GLSurfaceView,可以旋转触摸屏幕。我的应用程序的主要布局是FrameLayout。 frameLayout包含cameraView和GLSurfaceView。我的应用程序在屏幕上有两个按钮(放大/缩小),覆盖在cameraView上的RelativeLayout。

问题是摄影机视图与其他两个视图(缩放按钮和带多边形的GLSurfaceView)重叠,我只能在屏幕上看到cameraView。如果我从我的应用程序的主FrameLayout中删除cameraview,那么我可以看到GLSurfaceView和缩放按钮没有问题。

我该如何解决这个问题?我需要GLSurfaceView覆盖cameraView和RelativeLayout,缩放按钮覆盖GLSurfaceView ......

一些更新:

我在Android 2.2.2(motorola Droid)中检查过它完美无缺,但如果我在1.5到2.1的版本上进行测试,那么它的工作效果很差,相机视图会覆盖其他视图...

我还检查了如果我在我的应用程序的内容视图上反转视图的位置(首先是GLSurfaceView,在相机之后,最后是按钮),然后在Android 1.5到2.1上工作...但是然后不适用于Android 2.2.2及更高版本!我为此疯狂......

这是代码:

public class ARLambo3DSample extends Activity {
    private CustomCameraView cv=null;
    private ImageView minus;
    private ImageView plus;
    private MySurfaceView mySurfaceView;
    private boolean pressed=false; //algún boton de zoom pulsado
    private boolean zoomIn=false; //si zoomIn=true entonces hace zoomIn y si es false hace zoomOut
    private myThread t1; //Hilo que gestiona el zoomIn y el zoomOut

    public void onCreate(Bundle savedInstanceState) 
    {   
        super.onCreate(savedInstanceState);
        FrameLayout fl = new FrameLayout(this.getApplicationContext());
        cv = new CustomCameraView(this.getApplicationContext());
        RelativeLayout rl= new RelativeLayout(this.getApplicationContext());

        //turn off the window's title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        //fullscreen
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        fl.addView(cv);

        minus= new ImageView(getApplicationContext());
        minus.setImageResource(R.drawable.minus2);
        rl.addView(minus);

        plus= new ImageView(getApplicationContext());
        plus.setImageResource(R.drawable.plus2);
        rl.addView(plus);

        Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int w = display.getWidth();
        int h = display.getHeight();
        RelativeLayout.LayoutParams minusPosition = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        RelativeLayout.LayoutParams plusPosition = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

        minusPosition.leftMargin = (int)(w*0.77);
        minusPosition.topMargin  = (int)(h*0.80);  //0.66 si no es fullscreen
        minus.setLayoutParams(minusPosition);

        plusPosition.leftMargin = (int)(w*0.88);
        plusPosition.topMargin  = (int)(h*0.80);
        plus.setLayoutParams(plusPosition);

        mySurfaceView = new MySurfaceView(this);

        setContentView(fl);

        plus.setClickable(true); //esto es necesario para poder gestionar cuando el boton se presiona y se suelta
        minus.setClickable(true); //esto es necesario para poder gestionar cuando el boton se presiona y se suelta

        minus.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) 
            {
                switch(event.getAction())
                {
                    case MotionEvent.ACTION_DOWN: //boton presionado
                        zoomIn=false;
                        pressed=true; 
                        break;
                    case MotionEvent.ACTION_UP: //boton se suelta
                        pressed=false;
                        break;
                }
                return false;
            }
        });
        plus.setOnTouchListener(new OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) 
            {
                switch(event.getAction())
                {
                    case MotionEvent.ACTION_DOWN: //boton presionado
                        zoomIn=true;
                        pressed=true;           
                        break;
                    case MotionEvent.ACTION_UP: //boton se suelta
                        pressed=false;
                        break;
                }
                return false;
            }
        });

        t1= new myThread();
        t1.start(); 

        fl.addView(mySurfaceView);
        fl.addView(rl);

    }
    protected void onResume() {
        super.onResume();
        mySurfaceView.onResume();
    }
    protected void onPause() {
        super.onPause();
        mySurfaceView.onPause();
    }
}

1 个答案:

答案 0 :(得分:0)

我设法使用setZOrderMediaOverlay(boolean)方法使其工作。它会将您的GLSurface设置在相机表面的顶部。

http://developer.android.com/reference/android/view/SurfaceView.html#setZOrderMediaOverlay(boolean)