Admob ads not showing - Android - android

My ads don't display at all, I think I've followed the documentation correctly but they still won't show. The program is basically a webview and I want the ad to display at the bottom.
Heres my layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<WebView
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
</LinearLayout>
Any ideas?
EDIT: this is what I now have but it still doesn't appear to be quite right:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC" />
<WebView
android:id="#+id/webview"
android:layout_above="#id/ad"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</RelativeLayout>

Your Problem is that the WebView will take all the space on the screen and there is no space left for the ads.
A LinearLayout will distribute the space on a first come first serve rule. If the first View takes all the space the second view won't get any space..
I would use a RelativeLayout and add the adds first with a layout_alignParentBottom attribute and then add the webview with a layout_above="id for the adds". This will ensure that the adds are always on the bottom of the screen even if the webview wont take all the space at the moment and the webview will always be above the adds.

I had the same problem, i fixed it this way:
LinearLayout as main layout, inside it linearLayout(for the ad) and a webview, set wrap_content on the linearlayout for the ad, so, it will first show an ad and then the rest of the screen will be the webview.
example of mine:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="#+id/addmob"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
></LinearLayout>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>

<?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"
android:layout_width="fill_parent" android:id="#+id/rltvLayout1"
android:layout_height="fill_parent">
<LinearLayout android:id="#+id/linearLayoutwebview"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical">
<WebView android:id="#+id/webView1"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:fitsSystemWindows="true" />
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/ad_layout" android:layout_height="wrap_content"
android:gravity="bottom" android:layout_alignParentBottom="true"
android:layout_alignBottom="#+id/home_layout">
<com.google.ads.AdView android:layout_width="wrap_content"
android:layout_height="wrap_content" ads:adUnitId="put here your ID"
ads:adSize="BANNER" android:id="#+id/adView" ads:refreshInterval="60" />
</LinearLayout>
</RelativeLayout>

Related

ListView on TOP of Ads - Android

I'm having troubles showing ads on bottom of a listview, on my main activity the ads works, the only difference there is that I use a viewpager instead of listview.
This is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.ads.AdView
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:loadAdOnCreate="true"
android:background="#313131"
app:adSize="SMART_BANNER"
app:adUnitId="MY_ID" />
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/adView" />
</RelativeLayout>
The listview shows on TOP of the ads and of course can't be clicked, but this same layout works with a viewpager.
Another way.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<com.google.ads.AdView
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:loadAdOnCreate="true"
android:background="#313131"
app:adSize="SMART_BANNER"
app:adUnitId="MY_ID" />
</LinearLayout >
When Ad - is loaded, get his height. Then ListView bottomMargin = adHeight and Ad topMargin = (-1)*adHeight. Try it.
Final layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.google.ads.AdView
xmlns:app="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:loadAdOnCreate="true"
android:background="#313131"
app:adSize="SMART_BANNER"
app:adUnitId="MY_ID" />
<LinearLayout
android:id="#+id/listview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/adView" />
</RelativeLayout>
And then replaced:
getSupportFragmentManager().beginTransaction().add(android.R.id.content, list).commit();
With:
getSupportFragmentManager().beginTransaction().add(R.id.listview, list).commit();
<ListView
android:id="#id/android:list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
/>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#313131"
ads:loadAdOnCreate="true"
ads="SMART_BANNER"
ads="MY_ID" />
NB This is a layout question. It has nothing to do with Admob. If you are using a LinearLayout then just set layout_height="wrap+content" and layout_gravity="1" for the item that you want to expand to consume the unused space. In this case your ListView.
Your problem was really the layout_height="match_parent"
NB I also removed the unnecessary renaming of the ads namespace.

android layout overlay issue

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

Android admob ad on bottom below tabs in a tabview

I have a tab layout like this:
------------------
------------------
{1}----[2]-----[3]
Code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_weight="1"/>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:layout_marginBottom="-4dp"/>
</LinearLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/topLayout"
android:layout_gravity="bottom"
>
<!-- Ad Placeholder -->
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="MYID"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_gravity="top"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
/>
</RelativeLayout>
</TabHost>
My 3 tabs are on the bottom. However my ad overlaps them, is there a way to put the ad right underneath the tabs?
Check out this example from AdMob's Ad Catalog sample application. It involves wrapping the TabHost and ad around a RelativeLayout, aligning the ad to the bottom, and the TabHost above the ad.
You may want to take a deeper look at the sample application - it has other working examples on how to use AdMob in various layouts.

Great Issue with setting a button in landscape mode

I have an activity which is set up in the landscape mode and must remain this way(!So as an answer to my question don't tell me to set my activity in the PORTRAIT mode cause this is not a solution).
And I wanna put a button at the bottom of the screen like this:
http://i52.tinypic.com/30n9o5t.png
but I just can do it.All my attempts got me only this:
http://i53.tinypic.com/54acjs.png
Here is my xml file:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_camera"
/>
<Button android:id="#+id/btnPhoto"
android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take Photo !!"></Button>
</FrameLayout>
Don't forget my activity is in LANDSCAPE mode.
Thank you!
Using Image button instead.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
>
<SurfaceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/surface_camera"
/>
<ImageButton android:id="#+id/btnPhoto"
android:layout_gravity="right"
android:layout_width="your_button_width"
android:layout_height="your_button_height"
android:background="#drawable/your_button_here">
</ImageButton>
</FrameLayout>
The trick is done using layout_weight which is telling the layout to use all free space available. So you are creating two layouts the second with fixed height and the tell the first to use all the free space. This solution will work in both cases Landscape and Portrait mode.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_weight="1.0">
</LinearLayout>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="40dp">
<!-- place your buttons in this layout -->
</LinearLayout>
</LinearLayout>
UPDATE
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical"
android:layout_weight="1.0">
</LinearLayout>
<LinearLayout android:layout_width="40dp"
android:layout_height="fill_parent"></LinearLayout>
</LinearLayout>

Adding Admob into ScrollView -> AdBanner disappears

Hey folks
I managed to implement Admob into a normal linear layout so far.
Now I added a additional scrollview and the adbanner disappeared. I don´t know what I can do against it.
Follows the code from the .xml where I added the scrollview:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="match_parent">
<ScrollView android:id="#+id/scrollView1" android:layout_height="wrap_content" android:layout_width="match_parent">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical">
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</LinearLayout>
</ScrollView>
In my linear layout ,where the adbanner still works, the whole adbanner position was done in the main activitiy.java file (did this with help of the tutorial at taiic.com)
// Lookup R.layout.main
LinearLayout layout = (LinearLayout)findViewById(R.id.linearLayout);
// Create the adView
// Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
String pubID = "xxxxxxxxxxxxxxxxxx";
AdView adView = new AdView(this, AdSize.BANNER, pubID);
// Add the adView to it
layout.addView(adView);
// Initiate a generic request to load it with an ad
AdRequest request = new AdRequest();
request.setTesting(true);
adView.loadAd(request);
Can anybody tell me what to change or what code to add when implementing an admob banner into a scrollview?
edit:
i tried to add
<com.admob.android.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapprimaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"
android:alignParentBottom="true"/>
between last two lines in the .xml
</LinearLayout>
[here]
</ScrollView>
but then im getting the error "error: Error parsing XML: unbound prefix"
cheers
About the parsing error:
Is this a typo in the question? myapprimaryTextColor="#FFFFFF" instead of myapp:primaryTextColor="#FFFFFF" . This would give you the xml parse error.
About the layouts:
Use a RelativeLayout. The working code is at the end of the post. First, some theory :)
Your ScrollView is taking the whole screen, that's why you don't see the admob view. When the scrollview is defined, all the screen is availabel to it, so it takes it. The admob view is actually drawn below your screen. It can be reproduced in this example:
non-working layout
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ScrollView android:id="#+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
/>
</LinearLayout>
If you use a RelativeLayout instead, you can set it up so the admob is aligned to the bottom of the screen, and the scrollview above it, taking the rest of the available space.
working layout
<?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">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Test4"
android:id="#+id/test4"
android:layout_alignParentBottom="true"
/>
<ScrollView android:id="#+id/scrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_above="#id/test4"
>
<LinearLayout android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test1"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test2"
/>
<EditText
android:layout_width="fill_parent"
android:layout_height="300dp"
android:text="Test3"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
I used the admob xml version and that is what I use and it works. The ad is at the top. Just copy and paste and you will be scrolling along shortly.
<?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/com.yourproject.here"
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="a14dc1c9d6xxxxx"
ads:adSize="BANNER" />
<ScrollView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
[whole bunch of layout elements whoch shouldn´t affect the adbanner]
</ScrollView>
</LinearLayout>

Categories

Resources