Search code examples
androidadmobandroid-linearlayout

Admob ads dont show in Tabbed with Fragments Linearlayout


I am trying to implements ads on the bottom of my screen , someone told me I have to change the linearlayout to RelativeLayout but when i do that my Toolbar somehow become smaller and the tabs begin to look strange.So I think there might be some things I need to change or add to the relativelayout that I do not know Here is my Linearlayout down here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:app="http://schemas.android.com/apk/res-auto"
   xmlns:ads="http://schemas.android.com/apk/res-auto"

   android:orientation="vertical"
   tools:context="com.example.Jus.Forever.MainActivity">

   <android.support.v7.widget.Toolbar
       android:id="@+id/toolbar"
       android:layout_width="match_parent"
       android:layout_height="?attr/actionBarSize"
       android:background="?attr/colorPrimary"/>

   <android.support.design.widget.TabLayout
       android:id="@+id/tabs"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       app:tabGravity="fill"
       app:tabMode="fixed"
       android:background="@color/colorPrimary"/>

   <android.support.v4.view.ViewPager
       android:id="@+id/viewPager"
       android:layout_width="match_parent"
       android:layout_height="match_parent"/>

   <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_footer">
   </com.google.android.gms.ads.AdView>

</LinearLayout>

Solution

  • Since there isn't an image of what you want, I can only guess. But this should work:

    <?xml version="1.0" encoding="utf-8"?>
    <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:app="http://schemas.android.com/apk/res-auto"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        tools:context="com.example.Jus.Forever.MainActivity">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"/>
    
        <android.support.design.widget.TabLayout
            android:layout_below="@id/toolbar"
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabGravity="fill"
            app:tabMode="fixed"
            android:background="@color/colorPrimary"/>
    
        <android.support.v4.view.ViewPager
            android:layout_below="@id/tabs"
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>
    
        <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="12345">
        </com.google.android.gms.ads.AdView>
    
    </RelativeLayout>