I'm trying to display an admob banner in my listactivity but I'm running into problems. I followed the admob quickstart tutorial on the google developers website which uses relativelayout whilst I'm using linearlayout. I've tried tweaking my main xml according to previous answers on SO with varied results, sometimes the app stops/closes on launch and other times the listactivity remains blank. My original xml is
<?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:id="#+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<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"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
With that, the app runs fine but logcat says there's not enough space to display the ad, and when I move the adview above the listview the apps stops on launch. I've tried a different implementation with relativelayout as follows but this causes the app to close on launch as well
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_layout"
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="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
<LinearLayout
android:layout_alignParentTop="true"
android:layout_above="#id/adView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
<WebView
android:id="#+id/webview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
To request for the ad
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
Logcat for ads is
03-27 12:24:38.697: W/Ads(2094): Not enough space to show ad. Needs 320x50 dp, but only has 480x0 dp.
03-27 12:24:38.847: I/Ads(2094): Scheduling ad refresh 60000 milliseconds from now.
03-27 12:24:38.887: I/Ads(2094): Ad finished loading.
03-27 12:24:38.887: W/Ads(2094): Not enough space to show ad. Needs 320x50 dp, but only has 480x0 dp.
03-27 12:24:38.897: W/Ads(2094): Not enough space to show ad. Needs 320x50 dp, but only has 480x0 dp.
Please help. Thanks in advance
Use layout_weight, try something like this:
<?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:id="#+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:layout_weight="1"
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#null" />
<WebView
android:id="#+id/webview"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<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"
ads:adSize="BANNER"
ads:adUnitId="#string/banner_ad_unit_id">
</com.google.android.gms.ads.AdView>
</LinearLayout>
Related
I have two applications on Google Play using AdMob monetization. One is https://play.google.com/store/apps/details?id=karnagh.ammsoft.karnagh and the other is https://play.google.com/store/apps/details?id=componentspinout.ammsoft.componentspinout.
Both applications have similar number of impressions (around 5000 per day). But Kmap Solver (the first link) performs lower with around $0.1 RPM. Component Pinouts (the second link) have a $0.35 to $0.5 RPM and usually is more lucrative.
I'm posting both my layouts and code as a reference:
KMAP APP LAYOUT:
<LinearLayout 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">
<karnagh.ammsoft.karnagh.PageViewImage
android:id="#+id/pageIndicator"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:adjustViewBounds="true" />
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_weight="0.26"
android:fadeScrollbars="true"
tools:context=".MainActivity" />
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:clipToPadding="false"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
</LinearLayout>
COMPONENT PINOUTS APP:
<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:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="5dp"
android:paddingTop="5dp"
tools:context="componentspinout.ammsoft.componentspinout.MainActivity">
<ListView
android:id="#+id/componentsView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/adView"
android:paddingBottom="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:visibility="visible" />
<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="#string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>
</RelativeLayout>
The code to start ads is the same located on OnCreate of Activity:
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
My question is: Is there anything in my layout or code to improve APP RPM in Layout. Both Applications have AdView on the bottom of a Layout with SMART_BANNER setting.
Is it true that I need to set Location Permission so AdView object can select a better local AD?
Generaly for admob :
I'm simply showing one interstitial ad/session = low number of
impressions, high RPM. I could also spam my users with ads = high
number of impressions, low RPM. In the end you'll get the same result
but perhaps less annoyed users with the first method.
I think it's because of that
(From: http://forums.makingmoneywithandroid.com/advertising-networks/10955-tips-higher-admob-rpm.html)
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>
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>
I Want to load Google Ads in in AdView in Landscape mode. The ads are loading in Portrait mode but it is not loading in Landscape mode. Please Help
Here is my code for xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:orientation="vertical"
tools:context=".MainActivity" >
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/web1"
android:layout_weight="1"
/>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
ads:adUnitId="a151c14ed73ec5f"
ads:adSize="SMART_BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
android:gravity="center"
ads:loadAdOnCreate="true"
android:layout_weight="9" />
</LinearLayout>
And This code is written in Java:
AdView adView = (AdView)this.findViewById(R.id.adView);
adView.loadAd(new AdRequest());
Please Reply!
AdView is Showing but ads arw not shown in AdView.
You're using all your space for your webview:
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Use a RelativeLayout instead, and put the WebView "above" the AdView.
<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">
<WebView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/web1"
android:layout_above="#id/adView" />
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="a151c14ed73ec5f"
ads:adSize="SMART_BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
android:gravity="center"
ads:loadAdOnCreate="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
you should check the error log may be your adview is not getting proper space required for it..
I am a beginner in android.I made a flash game android app using a webview and integrated admob ad banner but it is overlaying the webview.I need it to appear like this pic http://i46.tinypic.com/2cosrjp.png
this is my code :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:id="#+id/lay"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a1513fab869115a"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
</RelativeLayout>
add android:layout_below="+id/lay" inside you webView view
<RelativeLayout
android:id="#+id/lay"
android:layout_below="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>
add android:layout_alignParentTop="true" in ads view
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
ads:adSize="BANNER"
ads:adUnitId="a1513fab869115a"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID" />
Even though RelativeLayout might be the first choice for many use cases, for this simple view I would use a LinearLayout, that's much easier.
i got the oppiste error, i want my app displayed as yours and i cant get it, i got the answer that u want.
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1">
<com.google.android.gms.ads.AdView android:id="#+id/adView"
android:layout_width="355dp"
android:layout_height="wrap_content"
ads:adUnitId="000000000000000000"
ads:adSize="BANNER"
android:layout_gravity="center_horizontal|bottom" />
<WebView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="#+id/tropas"
android:layout_weight="1.01" />
</LinearLayout>
this is my code and display Aadmob on top Not overlaying webview