0

I am pretty new to android. I am trying to add an admob banner at the bottom of an app, actually in two of the activities. I think Linearlayout is not the right way of doing it.

  1. So please help me Convert Linearlayout to RelativeLayout.

Also while running the app, only the activity_entry.xml sample-google-banner shows up. The view_home.xml banner just shows up static white space.

  1. And how do I make the banner smart? I mean I want it to show up only when theres a banner to be displayed, and not as a static blank space.

activity_entry.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:ads="http://schemas.android.com/apk/res-auto"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical">

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

<fragment
    android:id="@+id/entry_fragment"
    class="net.etuldan.sparss.fragment.EntryFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>

view_home.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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"
android:orientation="vertical"
tools:showIn="@layout/activity_home"
android:weightSum="1">

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

<fragment
    android:id="@+id/entries_list_fragment"
    android:name="net.etuldan.sparss.fragment.EntriesListFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
    android:layout_gravity="center_horizontal">
</com.google.android.gms.ads.AdView>

dejavu
  • 1
  • 4

1 Answers1

0

Here are some tips for getting what you want:

look here for making it into relativelayout: adMob | Smart banner at bottom?

basically, the key code is that you should have

android:layout_alignParentBottom="true"

You can nest your layout if it helps... or not.

Second part: consider using adListener and use onReceiveAd() and onFailedToReceiveAd() to dynamically format your layout.

Look here for some points on adListener:

How to know if AdMob ad has been loaded

Community
  • 1
  • 1
Andy
  • 337
  • 5
  • 16