I want to add second ads banner inside my LinearLayout but my app crashes when insert the second banner.Works well with the external banner into RelativeLayout,but i want to add second...inside ScrollView. What can i do?Here is my code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
/>
<ToggleButton
/>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxx"
ads:loadAdOnCreate="true"
>
</com.google.ads.AdView>
</LinearLayout>
</ScrollView>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxx"
ads:loadAdOnCreate="true"
>
</com.google.ads.AdView>
</RelativeLayout>
Do NOT displaying multiple Admob Adviews on a single page. It is against the terms of service. you signed up to Admob with. Unless you want to have your Admob account suspended.
You can add unlimited advertisements on your page . I don't think there is any limit for that. But its not recommended to do, according to admob rules there must be one advertisement on one page. And for every Adview you can need to define its seperate Layout that can be linear or relative.
Your application is crahing because you didn't set your TextView and ToggleButton Layout parameters. Remove them or set their Layout properties. Like
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
Related
I have created a my custom SurfaceView and now want to place admob on surface view. Not below or above because it reduces the screen size. I found many questions here but all are solving by putting SurfaceView below or above of the admob view. but I want to put admob on SurfaceView.
XML code of my Activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity" >
<com.scratchview.ScratchView
xmlns:wsv="http://schemas.android.com/apk/res-auto"
android:id="#+id/scratch_view_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
wsv:antiAlias="true"
wsv:revealSize="25dp"
wsv:scratchable="false" />
<com.scratchview.ScratchView
xmlns:wsv="http://schemas.android.com/apk/res-auto"
android:id="#+id/scratch_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
wsv:antiAlias="true"
wsv:revealSize="25dp"
wsv:scratchable="true" />
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:gravity="top"
ads:adSize="SMART_BANNER"
ads:adUnitId="#string/admob_id"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Note: I have tried by putting Admob below and above it is working fine. I need to put admob onto SurfaceView
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
http://i.stack.imgur.com/lbs7l.png
I'm trying to setup admob below the background, but I keep getting admob on top of the background like this .
http://i.stack.imgur.com/YJXU2.png
So what happened is I have a button alignedParentBottom="true"
but the ad is keep covering the button.
<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" >
<Button
android:id="#+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back"
android:textSize="40sp"
android:layout_alignParentBottom="true"
></Button>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/backButton"
>
<TextView
android:id="#+id/TextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="20sp"
android:text="#string/helphelp"></TextView>
</ScrollView>
<com.google.ads.AdView android:id="#+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="MY_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"
android:layout_below="#id/backButton"></com.google.ads.AdView>
You can create a second RelativeLayout - the inner one will have all of your main layout content, and the outer one will hold your layout content and the AdView. Simply set the AdView to the bottom, and set your RelativeLayout content above the AdView, and it will force the back button up when the ad comes back.
I have provided the code here for your convenience.
<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" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_above="#+id/adView2">
<Button
android:id="#+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/back"
android:textSize="40sp"
android:layout_alignParentBottom="true">
</Button>
<ScrollView
android:id="#+id/ScrollView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_above="#id/backButton">
<TextView
android:id="#+id/TextView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:textSize="20sp"
android:text="#string/helphelp">
</TextView>
</ScrollView>
</RelativeLayout>
<com.google.ads.AdView android:id="#id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adUnitId="MY_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true">
</com.google.ads.AdView>
</RelativeLayout>
Side note: Make sure your UI elements aren't too close to the ads; that may encourage accidental clicks, and is against AdMob's ToS.
Use a FrameLayout:
Child views are drawn in a stack, with the most recently added child on top.
There's nothing to it. If you want to ensure that the Button is drawn over the AdView, then place the AdView earlier in a common FrameLayout parent. E.g.,
<FrameLayout 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">
<com.google.ads.AdView android:id="#+id/adView2" ... />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
... Buttons, etc. ...
</RelativeLayout>
</FrameLayout>
Although you may want just the Button and AdView in a FrameLayout child of the RelativeLayout. Or you may want a RelativeLayout parent of the AdView in the example above, to position the ad.
How do I prevent my Android screen from shifting down when a page is view is displayed and receives the first add?
When the view is first displayed the screen is normal, then a ad is displayed and the screen shifts down a few lines.
Here is my code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background3"
android:orientation="vertical" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_gravity="top"
ads:adSize="BANNER"
ads:adUnitId="xxxxxxxxxx"
android:gravity="center"
ads:loadAdOnCreate="true" >
</com.google.ads.AdView>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="34dp" >
<EditText
android:id="#+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="Start" />
</TableRow>
</LinearLayout>
TIA, Trey
I don't have much experience with the ads. But from strictly a View standpoint it seems like what is happening is that the adView is set to View.GONE before it loads. Which means that its space is ignored when placing the other views into the parent.
I don't know for sure how you could get it to not do that. But I would try explicitly setting it to android:visibility="invisible" in your xml, then in your java you'll have to make it visible after it has loaded. "invisible" is like gone, but it tells the parent to respect the space that you will take up when you are visible.
Perhaps the loadOnCreate attribute causes the behavior you are seeing? Might also be worth trying it without that and just load it manually in your onCreate.
What I am trying to do is build a layout which if an AdMob Ad fails to load it shows one of my own Ads (ImageView) which are built into the app.
I cant seem to get the listview not to cover up my Ad.
I have no issue getting it to work if I just use the AdMob Ad alone.
Here is my layout.
<?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:layout_height="fill_parent"
android:background="#drawable/bgdark"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/actionbarLayout"
android:layout_width="fill_parent"
android:layout_height="#dimen/actionbar_height"
android:layout_alignParentTop="true"
android:layout_marginBottom="2dip"
android:background="#drawable/actionbar_background" >
//Top bar is here
</RelativeLayout>
<LinearLayout
android:id="#+id/layoutAds"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#00FF00"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true" >
<ImageView
android:id="#+id/ImageAlternativeAd"
android:layout_width="wrap_content"
android:layout_height="50dip"
android:layout_gravity="center_vertical"
android:src="#drawable/anad"
android:visibility="visible" >
</ImageView>
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="123456abcd"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR,CFFFFFFF9A836FD749F3EF439CD"
android:visibility="visible" />
</LinearLayout>
<ListView
android:id="#+id/listCategories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/adView"
android:layout_below="#id/actionbarLayout"
android:cacheColorHint="#00000000" >
</ListView>
This is exactly what you want.
https://stackoverflow.com/a/5188181/563306
Also, did you try with,
<ListView
android:id="#+id/listCategories"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/layoutAds"
android:layout_below="#id/actionbarLayout"
android:cacheColorHint="#00000000" >
</ListView>
I think a clean way to implement this would be to have a component that initially holds your com.google.ads.AdView view. Then, when you notice that your ad did not load, you can swap it with your ImageView on the fly.
Even better: make that a custom component. So from the "outside" (your layout) you are just including an instance of this component and internally, this component is implemented by either displaying an ad from AdMob or your own ad depending on whether the AdMob ad fails to load or not.