出现一个空框代替AdView(Android元素布局问题)

出现一个空框代替AdView(Android元素布局问题),android,xml,layout,admob,Android,Xml,Layout,Admob,我正在尝试将AdView放置到布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height=

我正在尝试将AdView放置到布局:

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

<LinearLayout
    android:id="@+id/home_layout"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"/>

</LinearLayout>

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"/>

</LinearLayout>

我做错了什么?提前感谢您。

以下是可能的错误

  • 您的横幅广告单元id不正确
  • 你没有在谷歌广告暴徒下面的链接上正确设置广告

  • 如果我的回答解决了您的问题,请投赞成票

    以下是可能的错误

  • 您的横幅广告单元id不正确
  • 你没有在谷歌广告暴徒下面的链接上正确设置广告

  • 如果我的回答解决了您的问题,请向上投票

    您已将内部
    线性布局的高度设置为
    匹配父项
    。这将消耗所有的可用空间,没有留给您的AdView,因此它会认为它不可见。将线性布局更改为:

    <LinearLayout
        android:id="@+id/home_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    

    您已将内部
    线性布局的高度设置为
    匹配\u父项
    。这将消耗所有的可用空间,没有留给您的AdView,因此它会认为它不可见。将线性布局更改为:

    <LinearLayout
        android:id="@+id/home_layout"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">
    

    我的问题得到了答案。XML是正确的,只是Adblock尚未在工作流中初始化。为此,我只需在onCreate操作中的activity adMob块中进行初始化:

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    
    还要导入已删除的库:

    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    

    感谢他人的帮助和建议。

    我的问题得到了答案。XML是正确的,只是Adblock尚未在工作流中初始化。为此,我只需在onCreate操作中的activity adMob块中进行初始化:

    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    
    还要导入已删除的库:

    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    

    感谢他人的帮助和建议。

    横幅id和其他内容正确无误,我在其他视图中使用相同的代码片段。:)横幅id和其他内容是正确的,我在其他视图上使用相同的代码片段。:)嘿,谢谢你的回复@William!不幸的是,情况并没有改变。我仍然看到广告的空盒子架,但广告本身并没有显示出来。嘿,谢谢你的回复@William!不幸的是,情况并没有改变。我仍然看到广告的空盒子架,但广告本身并没有显示出来。