adMob | Smart banner at bottom?

南笙酒味 提交于 2019-12-11 19:59:25

问题


The idea is to put the admob banner at the bottom of the screen I tried with android:layout_alignParentBottom = "true" but the banner stand in the middle of the place that it occupies. Currently looks like this: pic1 And I want to look like this: pic2

My code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background"
    android:orientation="vertical"
    tools:context="eu.gabrielatanasov.demoViewer.Home_activity" >

<LinearLayout
        android:id="@+id/homeContentLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin" >

App stuff here

</LinearLayout>
<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@id/homeContentLayout"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/adMob_ID" >
</com.google.android.gms.ads.AdView>

</RelativeLayout>

回答1:


I modified your layout a little bit, check this out:

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <LinearLayout
            android:id="@+id/homeContentLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_above="@+id/adView">
    </LinearLayout>
    <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignWithParentIfMissing="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="admobid">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>




回答2:


Edit your content_main.xml file like this:

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main">

    <FrameLayout
        android:id="@+id/fragmentContainer"
        android:layout_width="match_parent"
        android:layout_above="@+id/adView"
        android:layout_height="match_parent"
        android:orientation="vertical" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_home_footer">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>


来源:https://stackoverflow.com/questions/26095693/admob-smart-banner-at-bottom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!