Skip to content Skip to sidebar Skip to footer

Admob Under Floating Action Button

I have problem with position of floating action button. When i put ad from Admob fab is over it. I want to put ad under fab button but any method that I try does not work. Image of

Solution 1:

I suggest you to create layouts that contain the fab button from Android Studio's default layout.

After creating it, there are 2 layouts:

  1. contain_main.xml

  2. activity_main.xml

Edit activity_main.xml (I put some LinearLayout in order to able to set the orientation is vertical) like this :

activity_main.xml's code :

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.appschef.mobilequeue.floatingboat.MainActivity">



    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

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

    </android.support.design.widget.AppBarLayout>

    <include layout="@layout/content_main" />

    <!-- start from here-->
    <!-- LinearLayout for give space fab and AdView-->
    <LinearLayout
    android:orientation="vertical"
    android:gravity="bottom"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:orientation="vertical"
                android:layout_height="wrap_content">
                <!-- linearLayour for fab button-->
                <LinearLayout
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="right">
                    <android.support.design.widget.FloatingActionButton
                        android:id="@+id/fab"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="bottom|end|left"
                        android:layout_margin="@dimen/fab_margin"
                        android:src="@android:drawable/ic_dialog_email" />
                </LinearLayout>

                <!-- LinearLayour for AdView-->
                <LinearLayout
                    android:layout_weight="1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent">
                    <com.google.android.gms.ads.AdView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent">
                    </com.google.android.gms.ads.AdView>
                </LinearLayout>

            </LinearLayout>
    </LinearLayout>
    <!-- end from here-->

</android.support.design.widget.CoordinatorLayout>

I have tried it and it does work well.

enter image description here


Solution 2:

Instead of using a FrameLayout as the parent to your Ad layout, use a vertical LinearLayout. FrameLayout add it's children as frames. If you want to use it, then add a bottom margin to the content_main which should be equal or greater than the height of the Ad layout.


Solution 3:

The FrameLayout does it like so:

Child views are drawn in a stack, with the most recently added child on top.

So you need to add the fab after/below the AdView, if you want it to appear over it.


Post a Comment for "Admob Under Floating Action Button"