Jacques Krause
Jacques Krause

Reputation: 5569

Adview Below FrameLayout

I am switching through Fragments from my main activity. At the moment I am calling a new AdView from each Fragment but I only want to call one AdView from the main activity which shows across all the Fragments.

Now I just need to know how to get the AdView not to show inside the FrameLayout because now it is blocking the content at the bottom.

So how can I get the AdView outside/below the content in the FrameLayout ?

content_main.xml

<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:context=".activity.MainActivity"
tools:showIn="@layout/app_bar_main">


<FrameLayout
    android:id="@+id/mainFrame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</FrameLayout>

<RelativeLayout

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/mainFrame">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="15dp"
        android:layout_gravity="center"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

</RelativeLayout>

Upvotes: 0

Views: 730

Answers (1)

Jay Rathod
Jay Rathod

Reputation: 11255

Use only single Relative Layout as Root Layout and then use android:layout_above="@+id/adView" in Frame Layout.

Here is xml code .

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/adView"
        android:background="@mipmap/ic_launcher" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

enter image description here

Upvotes: 3

Related Questions