3

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

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

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

一些更新:

我检查过它在 Android 2.2.2(摩托罗拉 Droid)中运行良好,但如果我在 1.5 到 2.1 的版本上测试它,那么它运行不好,cameraview 与其他视图重叠......

我还检查了如果我在我的应用程序的 contentview 上反转视图的位置(首先是 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();
    }
}
4

1 回答 1

0

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

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

于 2013-10-18T09:41:38.720 回答