Android Admob广告未在带有片段的“活动”中显示。为什么? [英] Android Admob ad not shown in Activity with fragment. Why?

查看:95
本文介绍了Android Admob广告未在带有片段的“活动”中显示。为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动如下。
我使用 setContentView(R.layout.below)在另一个活动中启动它; 但是, below.xml 包含一个寻呼机(这是一个片段,具有自己的textview,webview等)。我的问题是,即使Google Ads块显示在Eclipse的图形布局中,并且当我运行以下所示的Java代码时也不会引发任何错误;我看不到广告。我不明白发生了什么!我已经尝试了很多事情,包括将布局更改为简单的相对布局。以下是我如何称呼此adView。

I have an activity as follows. I launch it inside another activity using setContentView(R.layout.below); However, below.xmlcontains a pager (which is a fragment and has its own textview, webview etc.). My problem is even though the Google Ads block is shown in the graphical layout on Eclipse and NO error is thrown when I run the java code shown below; I CAN NOT see the ad. I don't understand what is happening! I've tried so many things, including changing this layout to a simple relative layout. The following is how I call this adView.

    setContentView(R.layout.below);
    AdView mAdView2 = (AdView) findViewById(R.id.adView2);
    AdRequest adRequest2 = new     
    AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
            mAdView2.loadAd(adRequest2);

这是包含此adView的实际XML文件。

This is the actual XML file that contains this adView.

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

    <LinearLayout
        android:id="@+id/home_layout"
        android:layout_width="fill_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_above="@+id/footerLayout">
    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </android.support.v4.view.ViewPager>

    </LinearLayout>
    <LinearLayout
            android:id="@+id/footerLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="bottom"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            >
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="0dp"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="@string/banner_ad_unit_id" >
    </com.google.android.gms.ads.AdView>
    </LinearLayout>


</RelativeLayout>


推荐答案

尝试删除RelativeLayout的填充,应用程序,但在删除填充后可以正常工作

try removing the padding of RelativeLayout, also happens to my app, but got it working after removing the padding

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:paddingLeft="5dp"   <--- REMOVE
    android:paddingRight="5dp" > <--- REMOVE

如果必须使用填充,请将其添加到adview的父版式中,因此它将位于LinearLayout

if you must use a padding, add it on parent layout of the adview, so it will be on LinearLayout

这篇关于Android Admob广告未在带有片段的“活动”中显示。为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆