我的相机视图与 GLSurfaceView 重叠...但我希望它被 GLSurfaceView 覆盖
我有一个增强现实应用程序,可以显示相机视图和一个带有可以旋转触摸屏幕的多边形的 GLSurfaceView。我的应用程序的主要布局是 FrameLayout。 FrameLayout 包含cameraView 和GLSurfaceView。我的应用程序在屏幕上还有两个按钮(放大/缩小),位于覆盖cameraView的RelativeLayout上。
问题是cameraview与其他两个视图(缩放按钮和带有多边形的GLSurfaceView)重叠,我只能在屏幕上看到cameraView。如果我从应用程序的主 FrameLayout 中删除cameraview,那么我可以毫无问题地看到 GLSurfaceView 和缩放按钮。
我该如何解决这个问题?我需要 GLSurfaceView 覆盖cameraView,而带有缩放按钮的RelativeLayout 覆盖GLSurfaceView...
一些更新:
我检查过在 Android 2.2.2 (motorola 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();
}
}
I have an augmented reality app that shows the the camera view and a GLSurfaceView with a polygon that can be rotated touching the screen. The main layout of my app is a FrameLayout. The frameLayout contains the cameraView and the GLSurfaceView. My app also have two buttons on the screen (zoom in/out) on a RelativeLayout overlaying the cameraView.
The problem is that the cameraview is overlapping the other two views (the zoom buttons, and the GLSurfaceView with the polygon), i only can see the cameraView on the screen. If i remove the cameraview from the main FrameLayout of my app then i can see the GLSurfaceView and the zoom buttons without problems.
How can i solve this? i need that the GLSurfaceView overlays the cameraView and the RelativeLayout with the zoom buttons overlays the GLSurfaceView...
Some updates:
i checked that in Android 2.2.2 (motorola Droid) it works perfect, but if i test it on versions from 1.5 to 2.1, then it works bad, the cameraview overlapps the other views...
i checked also that if i invert the position of the views on the contentview of my app (first the GLSurfaceView, after the camera and finally the buttons), then works on android 1.5 to 2.1... but then doesn't works on android 2.2.2 and upper versions!!! i'm going crazy with this...
THis is the code:
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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法使用 setZOrderMediaOverlay(boolean) 方法使其工作。它将把你的 GLSurface 设置在相机表面的顶部。
http://developer.android.com/reference/android/ view/SurfaceView.html#setZOrderMediaOverlay(boolean)
I manage to make it works using the method setZOrderMediaOverlay(boolean). It will set your GLSurface on top of the camera surface.
http://developer.android.com/reference/android/view/SurfaceView.html#setZOrderMediaOverlay(boolean)