簡體   English   中英

在屏幕底部顯示AdMob標語

[英]Displaying AdMob banner at bottom of screen

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

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

我知道了!

更改包含adView的版式的重力:

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

在您的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>

將您的Java代碼替換為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獲得的

以此來提升您的adview代碼

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM