我有一个带有ViewPager的安卓应用程序,实现如下:
http://www.youtube.com/watch?v=C6_1KznO95A
我不知道如何在ViewPager下实现AdView。我已经尝试过以编程方式将AdView放在ViewPager下面。没有错误,但没有显示广告。
我的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>
</RelativeLayout>发布于 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"一起工作,那么结果应该是有效的。
<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>https://stackoverflow.com/questions/21053382
复制相似问题