![](/img/trans.png)
[英]How to add ad-mob (Advertisement banner) Top OR Bottom of the Imageview?
[英]Ad Mob Smart Banner does not work for all devices
我有一個布局,其中有一個網格視圖,我想在屏幕底部顯示橫幅廣告,我有以下代碼
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/backgroundColor"
android:fitsSystemWindows="true">
<include layout="@layout/detail_activity_bar"></include>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="60dp"
android:numColumns="2"
android:stretchMode="columnWidth"/>
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_gravity="bottom|center"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/home_banner">
</com.google.android.gms.ads.AdView>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
它適用於4英寸移動設備,但在較大的設備上,橫幅廣告與網格內容重疊。 如何使它對所有設備通用,使其不與應用程序內容重疊
嘗試以下布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:weightSum="1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#29000000"
android:orientation="vertical"
android:fitsSystemWindows="true">
<include layout="@layout/detail_activity_bar"></include>
<GridView
android:layout_weight="0.9"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/home_grid"
android:layout_width="match_parent"
android:layout_height="0dp"
android:horizontalSpacing="5dp"
android:verticalSpacing="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:numColumns="2"
android:stretchMode="columnWidth"/>
<com.google.android.gms.ads.AdView
android:layout_weight="0.1"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adViewGallery"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:layout_gravity="bottom|center"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/home_banner">
</com.google.android.gms.ads.AdView>
</LinearLayout>
只需使用LinearLayout或使用RelativeLayout而不是FrameLayout,它在所有設備上都是正確的! :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.