【问题标题】:Use an AdView with a ViewPager and a PagerTitleStrip使用带有 ViewPager 和 PagerTitleStrip 的 AdView
【发布时间】:2014-03-06 21:16:51
【问题描述】:

我的 Android 应用程序具有以下布局,但未显示广告。 在 logcat 中,我有关于“W/Ads:没有足够的空间来显示广告。需要 640x100,但只有 0x1038”的错误。

我的布局:

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

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

    <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="xxxxxxxx"/>
</LinearLayout>

我如何在 Oncreate 中加载广告:

    adView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice("xxxxxxx") //gnex
            .build();
    // Start loading the ad in the background.
    adView.loadAd(adRequest);

有什么想法吗?

【问题讨论】:

    标签: android android-layout admob


    【解决方案1】:

    改变这个。

    <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">
    
    <ViewPager
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
    <android.support.v4.view.PagerTitleStrip
        android:id="@+id/pager_title_strip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top" />
    </ViewPager>
    
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        ads:adSize="BANNER"
        ads:adUnitId="xxxxxxxx"/>
    </LinearLayout>
    

    【讨论】:

      【解决方案2】:

      现在似乎有足够的空间以线性布局向您展示广告。 做下面的事情。 1)要么给adview一些权重。 2)或者将线性布局改为相对布局,让adview有足够的空间展示。 3) 还要检查您是否收到了尺寸合适的广告。

      以下链接也可能对您有所帮助。

      AdMob "Not enough space to show ad" error

      【讨论】:

        【解决方案3】:

        我怀疑这是由于寻呼机的 layout_height 配置造成的。

        android:layout_height="0dp"
        

        试试改成

        android:layout_height="wrap_content"
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-08-31
          • 1970-01-01
          • 1970-01-01
          • 2013-04-13
          相关资源
          最近更新 更多