2012-01-12 54 views

回答

1

典型的解決方案是繪製3D場景,然後切換到正交投影並使用OpenGL繪製HUD。將普通組件放在OpenGL畫布上可能會產生不可預知的結果(它們可能閃爍或僅僅是不可見)。

2

可以在openGL佈局上添加一個或多個佈局。要做到這一點,你必須從RelativeLayout開始。它將包含OpenGL和Hud佈局。聲明順序很重要(首先聲明,首先呈現)。要更改Hud佈局的位置,可以使用layout_margin屬性,或者如果它是完整的疊加層,則使用match_parent。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/relativeLayout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <!-- START of OpenGL Layout --> 
    <LinearLayout 
     android:id="@+id/openGLLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginLeft="0dp" 
     android:layout_marginTop="0dp" > 
    </LinearLayout> 
    <!-- END of OpenGL Layout --> 

    <!-- START of HUD Layout --> 
    <LinearLayout 
     android:id="@+id/hudLayout" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="50dp" 
     android:layout_marginTop="50dp"> 
     <TextView 
      android:id="@+id/hudText" 
      android:text="Hud Text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" > 
     </TextView> 
    </LinearLayout> 
    <!-- END of HUD Layout --> 

</RelativeLayout> 

在這個例子中,OpenGL佈局是一個empy LinearLayout作爲容器使用。添加自己的GLSurfaceView這個RelativeLayout的由代碼:

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState) 

    setContentView(R.layout.main); 
    MyOpenGLSurfaceView view = new MyOpenGLSurfaceView(getApplication()); 
    LinearLayout openGLLayout = (LinearLayout)findViewById(R.id.openGLLayout); 
    openGLLayout.addView(mView); 
} 

我主要用這個方法進行確認彈出窗口或上下文菜單。這樣我就不必使用openGL創建自己的按鈕。

0

我遇到了同樣的問題,現在我打了近一年。我沒有使用XML的佈局,而是我添加的意見在Java中,像這樣:

,我得到了
rel.addView(camPreview, camParams); 
rel.addView(glView, glParams); 
rel.addView(imageView, imageParams); 

一個建議是,增添AZ索引參數去的addView調用像這樣:

rel.addView(camPreview, 0, camParams); 
rel.addView(glView, 1, glParams); 
rel.addView(imageView, 2, imageParams); 

,但沒有工作,要麼..

我甚至嘗試切換到XML佈局,但仍然沒有什麼,我到底該解決方案是希望

glView.setZOrderMediaOverlay(true); 
rel.addView(camPreview, camParams); 
rel.addView(glView, glParams); 
rel.addView(imageView, imageParams); 

注:setZOrderMediaOverlay(真),需要在您實際上添加視圖

嘗試,讓我知道這是否爲你的作品被調用。