0

i'm aware this might be duplicate but i didn't find my answer in the link provided below. my problem is pretty common i guess where floating action button is blocking banner Ad.

this my xml:

<?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.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" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/fab_margin"
        android:layout_gravity="bottom|right"
        app:srcCompat="@android:drawable/myicon1" />
</android.support.design.widget.CoordinatorLayout>

and this is my banner code in content xml:

<?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:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/app_bar_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="@string/FloatingAd" />


    <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"
    app:adSize="BANNER"
    app:adUnitId="@string/myBannerID" />
</RelativeLayout>

i tried the solutions provided in this link but it didn't match my need which is floating button needs to be above the banner with some space.

expected output:

enter image description here

Amod
  • 79
  • 7

1 Answers1

1

I have an idea you might use.

You can save the X and Y location of the floating button before he banner pops. Then you can get the measured Height and Width of the banner View and add set the Floating button Y to be equal to Banner.Height + previousX. This should just move the floating button above the banner view as desired. This also approach will also be helpful if you want to make some displacing animations when the banner pops up.

You should make use of TranslateX and TranslateY for a more natural approach.

  • this will work for some devices right ? i mean button might be in place different than other device based on screen size ! – Amod Sep 06 '20 at 11:46
  • yeah, X and Y are assigned and calculated depending on device screen size. Just like when you use view.GetLocationOnScreen() it will give you a value depending on your screen – eestevanell Sep 06 '20 at 19:22