AdMob的AD浏览报和ViewPager? [英] AdMob AdView and ViewPager?
问题描述
我的Android应用程序ViewPager实现的是这样的:
I have Android application with ViewPager implemented like this :
http://www.youtube.com/watch?v=C6_1KznO95A
我不知道如何实现以下ViewPager AD浏览报。 我试图把下面的ViewPager AD浏览报编程和XML。 有没有错误,但广告并未显示。
I don't know how to implement AdView below the ViewPager. I have tried to put AdView below the ViewPager programmatically and in xml. There is no errors but ads are not showing.
我的XML:
<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>
推荐答案
OK,你有几个问题。
OK, you have a couple of problems.
- 取向只与一个LinearLayout中。
- layout_alignParentBottom需要一个布尔值,而不是顶
- layout_weight只与一个LinearLayout中,也不RelativeLayout的
您有2个选项。使用RelativeLayout的,但首先定义与ViewPager定义为它上面的AD浏览或使用的LinearLayout,并有ViewPager使用layout_weight填补未使用的空间。
You have 2 options. Use a RelativeLayout but define the AdView first with the ViewPager being defined as above it OR use a LinearLayout and have the ViewPager fill the unused space using layout_weight.
由于RelativeLayout的
As RelativeLayout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_publisher_id"
ads:loadAdOnCreate="true" />
<android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_above="@+id/ad"
/>
</RelativeLayout>
或AS的LinearLayout
OR as LinearLayout
<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="match_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="@string/admob_publisher_id"
ads:loadAdOnCreate="true" />
</LinearLayout>
我个人会去与那感觉更简单的LinearLayout中。
Personally I'd go with the LinearLayout it feels simpler.
这篇关于AdMob的AD浏览报和ViewPager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!