2015-10-05 99 views
1
屏幕,而不是在底部顯示的頂部

AdMob標題顯示的底部。展示AdMob橫幅屏幕

這是我的代碼:

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); 

任何幫助表示讚賞。 謝謝。

+0

relace你的AD瀏覽代碼,您不必logcat的報道說,有沒有空間? – user2413972

+0

不,我沒有任何報告。 – bizzobaz

+0

它不會是一個例外,而只是一個信息。 Admob沒有說什麼? – user2413972

回答

0

我知道了!

更改包含AdView的佈局的嚴重性:

((layoutType) layout).setGravity(Gravity.BOTTOM); 
1

試試這個在您的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

+0

它的工作原理,但它涵蓋了我的主要佈局,所以我在屏幕底部有一個黑色的屏幕廣告。 – bizzobaz

+1

請附上您的XML代碼問題 – penta

+0

不幸的是我沒有一個XML文件,因爲我只有一個AbsoluteLayout(mLayout)progammatically增加。 – bizzobaz

0

與此

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_gravity="bottom" 
    ads:adSize="BANNER" 
    ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx"> 

</com.google.android.gms.ads.AdView> 
+1

首先他的問題已經有了一個可接受的答案。其次解釋爲什麼你的代碼應該解決問題,以便其他有類似問題的人可能會發現你的解決方案很有用。 –