2011-10-05 27 views
3

我有一個增強現實應用程序,顯示相機視圖和GLSurfaceView與可以旋轉觸摸屏幕的多邊形。我的應用程序的主要佈局是一個FrameLayout。 frameLayout包含cameraView和GLSurfaceView。我的應用在屏幕上還有兩個按鈕(放大/縮小),覆蓋cameraView的RelativeLayout。我的相機視圖重疊GLSurfaceView ...但我想它被覆蓋GLSurfaceView

問題是cameraview與其他兩個視圖(縮放按鈕和GLSurfaceView與多邊形)重疊,我只能看到屏幕上的cameraView。如果我從我的應用程序的主FrameLayout刪除cameraview,然後我可以看到GLSurfaceView和縮放按鈕沒有問題。

我該如何解決這個問題?我需要的是GLSurfaceView覆蓋的cameraView和RelativeLayout的變焦按鈕覆蓋的GLSurfaceView ...

有些更新:

我檢查,在安卓2.2.2(摩托羅拉Droid)它的作品完美,但如果我測試它的版本從1.5到2.1,然後它壞了,cameraview overlapps其他視圖...

我還檢查了,如果我顛倒對我的應用程序的內容查看意見位置(首先是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(); 
    } 
} 

回答