android - 设置页面底部的 AdMob 横幅

标签 android css admob android-linearlayout

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

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

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

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

主 Activity .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);

最佳答案

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

改为尝试:

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

关于android - 设置页面底部的 AdMob 横幅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23970747/

相关文章:

ios - 根据横幅 View 的外观调整布局

android - 动态更新 ViewPager?

android - Camera Intent,FileUriExposedException,将图像保存在存储中并检索图像位图和文件路径

html - CSS 效果添加为主动效果

gradle - 无法将 admob 添加到 libgdx 项目

swift - AdMob 显示测试广告但不显示真实广告 Swift/SwiftUI

android - 如何为启动器设置不同的标签而不是 Activity 标题?

java - android 新手问题 ArrayAdapter.setAdapter 上的空指针

javascript - Bootstrap Collapse.js 开关隐藏/显示菜单

html - 网站在 Windows 和 Mac 上定位元素的方式不同