2011-09-07 128 views
0

我想在我的GLSurfaceView上創建另一個視圖,我已經設法做到這一點,但由於某種原因,這一次沒有任何可見的。我做這一切的代碼,但下面是應該如何使用XML:爲什麼我的視圖不可見?

setContentView(R.layout.main); 
adLinearLayout = (LinearLayout)findViewById(R.id.AdLinearLayout); 

//If ad is found on server...Do this (view is passed into the method) 
LayoutParams layout = new LayoutParams(adLinearLayout.getMeasuredWidth(), (adLinearLayout.getMeasuredWidth()*10)/64); 
adView.setLayoutParams(layout); 
adLinearLayout.removeAllViews(); 
adLinearLayout.addView(adView); 

而且我的這種解釋是:

glView = new GLSurfaceView(this); 
glView.setRenderer(this); 
setContentView(glView); 
adLinearLayout = new LinearLayout(this); 
adLinearLayout.setGravity(Gravity.CENTER | Gravity.BOTTOM); 
this.addContentView(adLinearLayout, new LayoutParams(480, 150)); 

//If ad is found on server...Do This (view is passed into the method) 
LayoutParams layout = new LayoutParams(adLinearLayout.getMeasuredWidth(), (adLinearLayout.getMeasuredWidth()*10)/64); 
view.setLayoutParams(layout); 
adLinearLayout.removeAllViews(); 
adLinearLayout.addView(view, new LayoutParams(LayoutParams.WRAP_CONTENT ,LayoutParams.WRAP_CONTENT)); 

這絕不會顯示在屏幕上的視圖,雖然,有沒有有什麼缺失?

+0

您是否得到了解決方案? – sahu

回答

0

您需要使用framelayout將2個視圖堆疊在一起。

我不知道你如何得到與之前的linearlayout重疊。但根據定義,LinearLayout用於以水平或垂直順序聲明子視圖。

關於框架佈局,這是從Android文檔

子視圖在一個組中獲得,在頂部最近添加的孩子 。 FrameLayout的大小是其最大子項 (加上填充)的大小,可見與否(如果FrameLayout的父級允許)。

您也可以實現與RelativeLayout的某些重疊,但FrameLayout是正確的方法。

+0

雖然之前我已經在另一個頂部使用了linearlayouts,但試圖改變它,但它仍然不起作用 – Chris

+0

我更新我的答案 – blessenm

+0

我想實現TapJoy的SDK,並且他們也能夠使用LinearLayouts。在我之前的項目中,我在GLView的頂部添加了LinearLayout,但並非如此,我將多個佈局添加到LinearLayout – Chris