【问题标题】:Setup the bottom of the page AdMob banner设置页面底部的 AdMob 横幅
【发布时间】:2014-05-31 13:45:59
【问题描述】:

我正在尝试在页面底部设置 AdMob 横幅,但广告没有显示。 页面底部会出现空格,但 AdMob 不会在此处显示。

  1. 添加并引用 Google Play 服务库。 - 是的
  2. 在 AndroidManifest.xml 中添加元数据标记。 - 是的
  3. 在清单中声明 com.google.android.gms.ads.AdActivity。 - 是的
  4. 在清单中设置网络权限。 - 是的

有人告诉我为什么。 谢谢。

我的 XML

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <LinearLayout
        android:id="@+id/flContainer"                <!-- DATA Layout -->
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/ad_layout"
        android:orientation="vertical" />

    <LinearLayout
        android:id="@+id/ad_layout"                  <!-- AdMob Layout -->
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" />

</RelativeLayout>

MainActivity.java

// Create an ad.
adView = new AdView(context);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId(AD_UNIT_ID);

// Add the AdView to the view hierarchy. The view
// will have no size
// until the ad is loaded.
LinearLayout layout = (LinearLayout) findViewById(R.id.ad_layout);
//layout.getBottom();
layout.addView(adView);

// Create an ad request. Check logcat output for the
// hashed device ID to
// get test ads on a physical device.
AdRequest adRequest = new AdRequest.Builder()
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("INSERT_YOUR_HASHED_DEVICE_ID_HERE").build();

// Start loading the ad in the background.
adView.loadAd(adRequest);

【问题讨论】:

    标签: android css admob android-linearlayout


    【解决方案1】:

    您告诉 fldContainer 匹配父级。这意味着它将占用父级的所有空间,而不会为您的广告留下任何空间。

    改为尝试:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <LinearLayout
            android:id="@+id/flContainer"                <!-- DATA Layout -->
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:orientation="vertical" />
    
        <LinearLayout
            android:id="@+id/ad_layout"                  <!-- AdMob Layout -->
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:orientation="vertical" />
    
    </LinearLayout>
    

    【讨论】:

    • 如果您为“flContainer”使用布局权重,我建议该组件的高度为“0dp”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-24
    • 1970-01-01
    相关资源
    最近更新 更多