試試這個在您的XML。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<TextView
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.google.android.gms.ads.AdView
android:layout_alignParentBottom="true"
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="put ad id here">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
替換您的AdView代碼。
adView = new AdView(mSingleton);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId("ca-app-pub-xxxxxxxxxxxxxxx/xxxxxxx");
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXX")
.build();
adView.loadAd(adRequest);
mLayout.addView(adView, params);
有了這個
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
在XML您的AdView線android:layout_alignParentBottom="true"
是很重要的。放置並嘗試一下。
大多得到了它從https://developers.google.com/admob/android/quick-start
relace你的AD瀏覽代碼,您不必logcat的報道說,有沒有空間? – user2413972
不,我沒有任何報告。 – bizzobaz
它不會是一個例外,而只是一個信息。 Admob沒有說什麼? – user2413972