将AdView与ViewPager和PagerTitleStrip一起使用 [英] Use an AdView with a ViewPager and a PagerTitleStrip

查看:75
本文介绍了将AdView与ViewPager和PagerTitleStrip一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用程序具有以下布局,但未显示广告。
在日志中,我遇到有关 W / Ads:空间不足以显示广告。需要640x100,但只有0x1038的错误。

I have the following layout for my Android application, but the ads are not displayed. In the logcat, I have errors about "W/Ads﹕ Not enough space to show ad. Needs 640x100, but only has 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中加载广告:

How I load the ad in the 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);

有什么想法吗?

推荐答案

更改此内容。

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

这篇关于将AdView与ViewPager和PagerTitleStrip一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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