2015-10-05 104 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

首先他的问题已经有了一个可接受的答案。其次解释为什么你的代码应该解决问题,以便其他有类似问题的人可能会发现你的解决方案很有用。 –