i have created a game(surfaceview) and i am trying to implement admob wherein it must be fixed at the bottom.. i have successfully implemented the admob and shows it properly but what i did is i call it in main activity.
AdView adView = (AdView)findViewById(R.id.adView);
adView.loadAd(new AdRequest());
and i have this on all layouts
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="#string/unit_id"
ads:loadAdOnCreate="true"
/>
what i need to do is show the admob but it will not be affected even if the screen switches it is fixed in the bottom part of the screen. i have searched for some thing like this but i have no success. i hope someone can help or even explain on how i can achieve this.
P.S. its like 1 banner for all activities.
I think it will be difficult (or impossible) to have just a single unique banner span multiple Activities. The ActivityGroup group class may have allowed this kind of thing, but it was never popular and anyway has been deprecated for a while.
Meantime there remains plenty of demand for the UX motif of switching between major views within the confines of one screen. But the mechanism has been reworked to use Fragments. If you can make your SurfaceView stuff work within a Fragment, then that might be your best bet. A layout might look something like this:
<LinearLayout>
<Fragment>
<AdView>
<LinearLayout>
When I did this kind of thing recently, I just put the AdMob code at the bottom of every Activity, and let it reload a fresh ad with every push. There has been no scolding from the Google side regarding too-frequent ad requests, and I am getting plenty of clicks.
Good luck!
Use Only Xml Coding without Java Code
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<com.google.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Can you wrap the whole screen in a relative layout? You can then align the banner to the parent's bottom. You other items should be declared with layout_above to keep them above the banner. The easiest way is to wrap them in another layout.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/adView" >
... your other items can go here
</RelativeLayout>
<com.google.ads.AdView
android:id="#id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="App ID"`enter code here`
ads:testDevices="25"
ads:loadAdOnCreate="true" />
</RelativeLayout>
Related
In admob management AdUnit shows in format
ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn
How am i suppose to put it in xml layout?
Is this correct?
<com.google.android.gms.ads.AdView
android:id="#+id/ad1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn"
/>
You already have the correct Ad unitId..
It should be something like "ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn"
I am developing my first Android app. Although I have 15 years of Java software development experience, Android is new to me. My desired look is a background image with other images on top of it, as well as labels and phone numbers. It seems like the best way to accomplish this is a Linear Layout for the background image, with a nested layout for the other fields on top of that. I have searched online and cannot find any sample code on how to accomplish this. Any recommendations would be greatly appreciated. Thanks in advance.
What are you using to develop? If you are you using Eclipse with the Android SDK this is super easy. Put the desired picture in the appropriate drawable folder, go to the graphical view of layout that corresponds to your activity, on the right side of the screen there is a list of all the properties, find background, then select your picture from drawables. You can also do this from the xml using android:background="#drawable/yourPic". This way you don't have to worry about having things layered on top of it.
I think you should go through followings:
1. http://phandroid.com/2011/05/11/10-tips-for-android-ui-design/
2. http://mobile.tutsplus.com/series/android-user-interface-design/
3. http://coding.smashingmagazine.com/2011/06/30/designing-for-android/
4. http://android-developers.blogspot.in/2011/09/thinking-like-web-designer.html
If I got, something like this can work:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<stuff>
</RelativeLayout>
<stuff>
</RelativeLayout>
I used it in an app, and made the trick.
First of all, RelativeLayout is the best layout to use. It depends on your design.
If your design says to keep all the views either vertically OR horizontally, you can use LinearLayouts in between.
My suggested way:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Horizontal">
<View1 />
<View2 />
</LinearLayout>
</LinearLayout android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_parent"
android:orientation="Vertical"
android:layout_below="#id/layout1">
<View3 />
<View4 />
</LinearLayout>
</RelativeLayout>
Which will yield you something like this
So, I currently have an AdView in my layout like this:
<com.google.ads.AdView
android:id="#+id/ad"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adUnitId="XXXXXXXXXXXXXX"
ads:adSize="BANNER"
ads:loadAdOnCreate="false"/>
and that works just fine. However, I have to get the AdView in the source code in order to pass it a request for the Emulator and my personal phone to be TestingDevices and not receive real ads. Is there a way I can list those in the XML directly? or even force the AdView to ONLY show test ads, so that I don't have to have that chunk of code and can set the AdView to loadAdOnCreate?
Thanks.
Sure, add this to the xml:
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
I found it here: https://developers.google.com/mobile-ads-sdk/docs/android/banner_xml
I've got a problem with Admob not showing up Ads...
Here's the LogCat:
WARN/AdMobSDK(502): Ignoring requestFreshAd() because we are requesting an ad right now already.
INFO/AdMobSDK(502): No fill. Server replied that no ads are available (1164ms)
INFO/AdMobSDK(502): No fill. Server replied that no ads are available (846ms)
I've tried test mode, no test mode, emulator, real phone, etc. It never shows anything up, but I get requests and prints on Admob stats, like if it ever worked...
AFAIK, I did everything in the Admob Android SDK... the only thing that could be the cause of any problems, IMHO, would be the fact that I'm using tabbed layout with scrollview and then a relativelayout where the ad shows...
Here's a sample of the layout for a tab:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.xxx.xxx"
android:id="#+id/tababout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:padding="10px">
<ImageView
android:id="#+id/label_img"
android:src="#drawable/about_header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="centerInside" />
<TextView android:id="#+id/label_know_more_desc"
style="#style/Desc"
android:layout_below="#id/label_img"
android:text="#string/tab_about_know_more_desc" />
<Button android:id="#+id/bt_know_more"
style="#style/Button"
android:gravity="center_vertical|center_horizontal"
android:layout_below="#id/label_know_more_desc"
android:text="#string/tab_about_know_more_bt" />
<com.admob.android.ads.AdView android:id="#+id/ad" android:layout_width="fill_parent" android:layout_height="wrap_content" myapp:backgroundColor="#000000" myapp:primaryTextColor="#FFFFFF" myapp:secondaryTextColor="#CCCCCC" />
</RelativeLayout>
</ScrollView>
And here's the main.xml, not that I think you need it:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF000000"
android:paddingTop="5px">
</FrameLayout>
</LinearLayout>
</TabHost>
I've read in Admob ads will not display when placed inside a tabview that the problem could be the 10px padding I'm throwing in, but even if I disable that, it doesn't work.
I even tried moving the xmlns:myapp to RelativeLayout, but obviously didn't change anything....
Also, I've made my first live ad request over 24 hours ago...
EDIT
Ok, now I'm getting somewhere, I've managed to get test ads showing up (my setTestDevices was too late in the onCreate code, I pushed it up to the first lines), but not real ones... am I missing something? I obviously commented out the setTestDevices line and no ads show up
EDIT 2
Well, I added two internal ads (I already had internal ads enabled, but no internal ads set), and suddenly ads started showing on my app (not only internal ads).
I guess everything altogether made it work?! :)
Thanks everyone!
You aren't positioning the ad's in the RelativeLayout (they need a layout_above or layout_below or whatever to specify where to put them).
Also there is a minimum size for admob that you might want to ensure you match, I think it's like 48dip in height at least, not sure what the horizontal is.
Lastly I don't know where you are trying to place your ad's, but it probably would make more sense in your main frame-layout, I have a padding at the bottom of my app which I use for the ad-view.
Edit: also if your app is public check for ad-revenue. Android pre 2.3 allowed ad's to be hidden behind views and still register clicks. I actually made my initial $1 before my ad's were even visible by anyone.
Another reason that the AdMob Ads won't show up is that you haven't declared the AdActivity which will display the ads when they are clicked on. Without the AdActivity declared in my AndroidManifest.xml, I don't see the ads. With it declared, the Ads show up.
...AndroidManifest.xml...
<!-- AdMob -->
<activity android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
In my Android app, I have a tabbed Activity. In one of the tabs I have two TextViews and two EditTexts.
The first EditText is only one line, and that's fine. However, I want the other EditText, android:id="#+id/paste_code", to take up the remaining space, but no matter what I do to it, it will only show one line. I don't want to manually set the number of lines, since the number that would fit on the screen differs based on your device.
Here's the relevant code. It's nested inside all the necessary components for a tabbed Activity.
<ScrollView
android:id="#+id/basicTab"
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:layout_weight="1" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Paste title"
android:layout_weight="0" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/paste_title_hint"
android:id="#+id/paste_title"
android:lines="1"
android:gravity="top|left"
android:layout_weight="0" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Paste text"
android:layout_weight="0" />
<EditText
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="#string/paste_hint"
android:id="#+id/paste_code"
android:gravity="top|left"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
Since the accepted answer doesn't address the situation fully, here's a proper fix for people coming to this while searching:
Firstly, Romain Guy from the Android dev team addresses this well in this blog post:
http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/
Essentially, your ScrollView needs to contain the android:fillViewport="true" attribute.
If things aren't working once you've done that, here are a couple of things to check:
The layout inside the ScrollView (such as a LinearLayout) needs to have layout_height="wrap_content"
The view(s) you want to expand should have layout_height="wrap_content"
The view(s) you want to expand should have layout_weight="1.0" or similar
Don't forget to set minLines="3" or similar in the view(s) you want to expand if you don't want it/them to shrink too much.
The problem seems to come from your use of ScrollView. I've tested your code using a ScrollView as the parent container, and got the same problem. However if I replaced the ScrollView with a LinearLayout, then the second EditText properly expanded to fill the whole screen. The problem must be that ScrollViews are designed to wrap to their smallest possible size, regardless of what settings you put in android:layout_height. I experimented with another few layouts, e.g. a RelativeLayout using layout_above and layout_below, but those only affected its maximum size, not its size when empty. Unfortunately, that means I'm not sure how to solve your problem... Is there a way you can redesign your layout to use something other than the ScrollView as the parent container?