Question

I try to make android app with AdMob.

I create the admob adView as described in documentation:

FrameLayout layout = (FrameLayout) findViewById(R.id.frame_layout);
adView = new AdView(this, AdSize.SMART_BANNER, myAdMobId );

Then, if I run my app on a device 320x480 (phone), the advert banner appears on the top, but if I run my app on a android tablet 1280x800, the advert banner appears centered horizontally and vertically - at the center of screen.

Also, I tried AdSize.BANNER, AdSize.IAB_BANNER, AdSize.IAB_LEADERBOARD - result is the same.

What I am doing wrong?

UPD1. res/layout/main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frame_layout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<com.mysite.myapp.GameView
      android:id="@+id/game"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>    
</FrameLayout>
Was it helpful?

Solution

This should do the trick.

     FrameLayout.LayoutParams adsParams =new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, 
            FrameLayout.LayoutParams.WRAP_CONTENT, android.view.Gravity.TOP|android.view.Gravity.CENTER_HORIZONTAL); 

    layout.addView(adView, adsParams);

in what you did in the xml, you didn't specify any gravity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top