首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AdView和ViewPager

AdView和ViewPager
EN

Stack Overflow用户
提问于 2014-01-11 04:00:35
回答 1查看 974关注 0票数 1

我有一个带有ViewPager的安卓应用程序,实现如下:

http://www.youtube.com/watch?v=C6_1KznO95A

我不知道如何在ViewPager下实现AdView。我已经尝试过以编程方式将AdView放在ViewPager下面。没有错误,但没有显示广告。

我的xml:

代码语言:javascript
复制
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

<android.support.v4.view.ViewPager
 android:id="@+id/pager"
 android:layout_width="match_parent"
 android:layout_alignParentBottom="top"
 android:layout_height="0dp"
 android:layout_weight="1"/>

<com.google.ads.AdView
 android:id="@+id/ad"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentLeft="true"
 android:layout_alignParentRight="true"
 android:layout_alignParentBottom="true"
 android:layout_below="@+id/pager"
 ads:adSize="BANNER"
 ads:adUnitId="@string/admob_publisher_id"
 ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
</RelativeLayout>
EN

回答 1

Stack Overflow用户

发布于 2014-01-11 04:07:21

首先,RelativeLayout没有android:layout_weight

其次,RelativeLayout没有android:orientation

如果您想使用这些,请使用LinearLayout,而不是RelativeLayout。如果这样做,就去掉AdView中的三个android:layout_alignParent*属性以及android:layout_below,因为这些属性是用于RelativeLayout的,而不是LinearLayout的。

假设AdView可以与android:layout_height="wrap_content"一起工作,那么结果应该是有效的。

代码语言:javascript
复制
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical">

  <android.support.v4.view.ViewPager
   android:id="@+id/pager"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1"/>

  <com.google.ads.AdView
   android:id="@+id/ad"
   android:layout_width="wrap_content"
   android:layout_height="wrap_content"
   ads:adSize="BANNER"
   ads:adUnitId="@string/admob_publisher_id"
   ads:loadAdOnCreate="true" >
  </com.google.ads.AdView>
</LinearLayout>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21053382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档