AdMob ads taking up all screen space - android

After long hours of problems with getting ads to work it finally works.
But now my AdMob ads add a black background in its view/layout(I don't know)
So my game isn't visible anymore. The size of the ad itself is exactly how I want it,
but I need to get rid of this weird black background.
I suspect that I'm doing something wrong with layouts:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-4118138803752321/8641047294"
android:orientation="vertical" />
</RelativeLayout>
What exactly is going wrong?

Because it's a RelativeLayout please assign the position of the AdView and that should take care of your issue.

Specify the position for your Adview within the RelativeLayout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-4118138803752321/8641047294"
/>
</RelativeLayout>

Related

Android Admob ad not shown in Activity with fragment. Why?

I have an activity as follows.
I launch it inside another activity using setContentView(R.layout.below); However, below.xmlcontains a pager (which is a fragment and has its own textview, webview etc.). My problem is even though the Google Ads block is shown in the graphical layout on Eclipse and NO error is thrown when I run the java code shown below; I CAN NOT see the ad. I don't understand what is happening! I've tried so many things, including changing this layout to a simple relative layout. The following is how I call this adView.
setContentView(R.layout.below);
AdView mAdView2 = (AdView) findViewById(R.id.adView2);
AdRequest adRequest2 = new
AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
mAdView2.loadAd(adRequest2);
This is the actual XML file that contains this adView.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="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:orientation="vertical"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<LinearLayout
android:id="#+id/home_layout"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#+id/footerLayout">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
</LinearLayout>
<LinearLayout
android:id="#+id/footerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="bottom"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id" >
</com.google.android.gms.ads.AdView>
</LinearLayout>
</RelativeLayout>
try removing the padding of RelativeLayout, also happens to my app, but got it working after removing the padding
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="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:orientation="vertical"
android:paddingLeft="5dp" <--- REMOVE
android:paddingRight="5dp" > <--- REMOVE
if you must use a padding, add it on parent layout of the adview, so it will be on LinearLayout
Give some heights to ad view it's height depends on device screen size it can be 50dp,120dp
use this if nothing happens then please put different size and try one more time
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="#+id/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#+id/footerLayout">
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</android.support.v4.view.ViewPager>
</LinearLayout>
<LinearLayout
android:id="#+id/footerLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
>
<com.google.android.gms.ads.AdView
android:id="#+id/adView2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_marginBottom="0dp"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id" >
</com.google.android.gms.ads.AdView>
</LinearLayout>

AdMob banner at bottom - Converting Linearlayout to RelativeLayout

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.
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.
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>
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

Banner doesnt show on the screen only graph

I have one problem if i use this code i cant see google AdView i dont know where is it :( Whatever i make it wasnt show but the banner in first page working good but this in second not :( Can anyoune suggest me
<?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:id="#+id/graph"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
ads:adSize="BANNER"
ads:adUnitId="#string/ad_unit_id" />
<com.calculator.grap.GraphPanel
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="#drawable/ic_launcher" />
</LinearLayout>
As it is a vertical layout it show on the top.Moreover you should not be using match_parent for both width and height of AdView.
You should use height as 0dp if you are using layout_weight.
Change the height of GraphPanel to 0dp.
Also rephrase your question in a better way.

How do I make sure my webview can scale with devices?

I'm trying to get my webview to sit just above my Google Ad Mob ad. However the web view always covers the entire screen unless I programatically try and adjust the height. I've tried setting the height of the webview to the heigh of the screen subtracting my ad height, but that doesn't seem to work accurately on all devices. What should my height of my webview be set to if I want my ad to sit just below the webview?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/linearLayout">
<WebView
android:id="#+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="320dip"
android:layout_height="50dip"
ads:adUnitId="/serviceid/myadtagishere"
ads:adSize="BANNER"
android:layout_below="#+id/webView1"/>
</RelativeLayout>
Try this :
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="320dip"
android:layout_height="50dip"
ads:adUnitId="/serviceid/myadtagishere"
ads:adSize="BANNER"
android:layout_alignParentBottom="true"/>
The add view should be above the webview and the webview fullscreen.
I was able to fix the problem using a linear layout. This seems to be the easiest and most effective way of getting a google ad mob ad to show up below a webview.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/linearLayout"
android:orientation="vertical">
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="50dip"
ads:adUnitId="/5773/sci.app.hoosierscoop"
ads:adSize="BANNER"/>
</LinearLayout>

ListView taking up all space, when trying to use an Admob Adview in Android

I am trying to get Google Admob advertisements to display on the main screen of an app that consists of a ListView. Unfortunately, the ListView is taking up all of the space on the screen, and then the advertisement appears over the top of it. I have tried putting the ListView at the top, followed by an AdView, and I've also tried putting the AdView at the top, followed by the ListView, but nothing works.
If I set the size of the LinearLayout enclosing the ListView to a fixed height (eg, 200px) then it it limits the size and fixes the problem, but I don't want to do this, because screen heights of Android devices vary so much. Is there no way to tell the ListView to not take up all the space without setting a fixed size?
My code is below, I'd be grateful for any help:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_alignParentTop="true"
android:id="#+id/ad_layout"
android:orientation="vertical"
android:gravity="top"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_alignParentBottom="true"
android:layout_below="#+id/ad_layout"
android:orientation="vertical"
android:gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no_hosts"/>
</LinearLayout>
</RelativeLayout>
Both of your LinearLayouts have height of fill_parent. That means that they'll both be the full height of their parent. Clearly not what you want. Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.ads.AdView android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="AD_UNIT_ID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
<ListView android:id="#id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<TextView android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/no_hosts"/>
</LinearLayout>
You have a relative layout. you need to set the listview property to layout_below="yourAdLayout" or rename the parent layout to linear layout. the orientation flag is not used in a relative layout, only in linear.

Categories

Resources