<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>
答案 0 :(得分:2)
您必须将layout_alignParentBottom
设置为true
创建RelativeLayout
作为父级,并放置GridView
和AdView
<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
放在Top
和AdView
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>