Search code examples
androideclipseadmobadview

Android Admob 4.3.1 how do I make the adView show on top of the screen?


I've been looking at similar questions but they are more on how to get the ads to show up with this new Admob version, I'm getting ads to show so thats not my problem, my problem is that ads show in the bottom of the screen so when the app expands the content on the screen the adview disappears since it goes under all the content. my solution is to place the adview on top of the screen and that way no matter how much content is on the screen the adview will be visible! I was able to accomplish this before when the adview was embedded into my xml, but following the admob tutorial you don't put it on the xml anymore. So how can I place the Ad on top of the mainLayout? here is the code I have been trying.

    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);
    adView = new AdView(this, AdSize.BANNER, "my code");
    layout.addView(adView);
    AdRequest r = new AdRequest();
    adView.loadAd(r);
    // this is what I try to get it on top of the screen, but is not working
    adView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
    adView.bringToFront();

this is all since I haven't done anything to the XML, is still showing the adview in the bottom, so how can I get it on the top part of the screen? Thanks


Solution

  • Your code is setting the gravity of the AdView, but the AdView is within a LinearLayout. Place the LinearLayout where you want it to appear.