[英]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.