如何在底部显示Admob广告?

时间:2014-04-29 18:26:17

标签: android android-layout

你可以告诉我如何在屏幕底部显示admob广告吗?我尝试了一些方法,但广告一直显示在页面顶部。这是xml

<com.google.android.gms.ads.AdView
    android:layout_alignParentTop="true"
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    ads:adUnitId="@string/ad_id"
    android:visibility="@string/ad_visibility"
    ads:adSize="BANNER"
    android:background="#463B39"/>

<GridView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_list_margin"
    android:paddingRight="@dimen/activity_horizontal_list_margin"
    android:paddingTop="@dimen/activity_vertical_list_margin"
    android:paddingBottom="@dimen/activity_vertical_list_margin"
    android:divider="@null"
    android:clipToPadding="false"
    android:numColumns="2"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth">

</GridView>

1 个答案:

答案 0 :(得分:2)

您必须将layout_alignParentBottom设置为true

创建RelativeLayout作为父级,并放置GridViewAdView

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

<com.google.android.gms.ads.AdView
    android:layout_alignParentBottom="true"
    android:id="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

<GridView
    android:id="@+id/listView"
    android:layout_above="@+id/adView"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

</GridView>

</RelativeLayout>

编辑:

使用LinearLayout的另一种方式。创建父垂直LinearLayout并将GridView放在TopAdView Bottom

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:ads="http://schemas.android.com/apk/res-auto"
      android:orientation="vertical">

<GridView
  android:id="@+id/listView"
  android:layout_width="wrap_content"
  android:layout_height="match_parent"
  android:background="@color/Red"
  android:layout_weight="2"/>

<com.google.android.gms.ads.AdView
   android:id="@+id/welcomeAdView"
   android:layout_width="match_parent"
   android:layout_height="100dp"
   ads:adSize="SMART_BANNER"
   ads:adUnitId=""
   android:layout_weight="1"/>
</LinearLayout>