Akashdeep Singh Akashdeep Singh - 1 year ago 99
Android Question

Admob add at bottom

I'm working on an app and I've have Admob and i want to add at bottom of my layout. I'm using Appcompat toolbar. Using android:layout_marginTop is not a good idea. Below i've posted the Main.xml where i'm using admob integration in the app and the Toolbar which is made by using AppCompat Toolbar is also mentioned below as Toolbar.xml

Main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:background="#212121"
tools:context=".MainActivity">

<include
android:id="@+id/tool_bar"
layout="@layout/tool_bar"
></include>


<ImageButton
android:id="@+id/btnSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="200dip"
android:src="@drawable/btn_switch_on"
android:background="@null"
android:contentDescription="@null"
/>

<com.google.android.gms.ads.AdView

android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btnSwitch"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"

ads:adSize="BANNER"
ads:adUnitId="@string/banner">
</com.google.android.gms.ads.AdView>

</RelativeLayout>


Toolbar.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar 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="wrap_content"
xmlns:ads="http://schemas.android.com/tools"
android:background="#000"
android:elevation="4dp"
app:contentInsetStart="150dp"
app:titleTextAppearance="@style/Toolbar.TitleText"

>

</android.support.v7.widget.Toolbar>

Answer Source

Use only this : android:layout_alignParentBottom="true"

Remove this : android:layout_below="@+id/btnSwitch"