你應該修改你的佈局是這樣的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layoutMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout1"
android:tag="trueLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
>
</RelativeLayout>
</LinearLayout>
這是我的代碼,這是自我解釋:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layoutMain = (LinearLayout) findViewById(R.id.layoutMain);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
adView = new AdView(this, AdSize.BANNER, "YourPersonalID#");
layoutMain.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
RelativeLayout layout1 = (RelativeLayout) findViewById(R.id.layout1);
layout1.setOnTouchListener(this);
mTestHarness = new GLSurfaceView(this);
mTestHarness.setEGLConfigChooser(false);
mTestHarness.setRenderer(this);
mTestHarness.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
layout1.addView(mTestHarness);
}
你得到這個權利之後,您將獲得相當於從谷歌播放教程的BannerEssentials教程應用程序,但使用GLSurfaceView代替。
你的佈局是什麼樣的? –
我設置在java代碼中的佈局不是xml文件,下面是代碼 AdView mAdView = new AdView(this,AdSize.BANNER,「id」); FrameLayout layout = new FrameLayout(this); //(FrameLayout)this.findViewById(R.id.adViewLayout);我們可以使用FrameLayout.LayoutParams來創建一個新的FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,FrameLayout.LayoutParams.WRAP_CONTENT,android.view.Gravity.BOTTOM | android.view.Gravity.CENTER_HORIZONTAL); \t layout.addView(GLGame.mAdView,adsParams); \t mAdView.loadAd(new AdRequest()); – appdroid
你把你的GLSurfaceView添加到同一個FrameLayout中嗎?如果是的話,你可以發佈該代碼。如果你不是那麼這就是你的問題。 –