Question

I am working on the android app. I tried to add a banner at the bottom of the screen.

However, in the run time, it show the warning

Not enough space to show ad! Wants: <936, 120>, Has: <720, 988>

That seems the screen is not long enough. Do I need to write the program or I need to adjust the size in the panel (there seems to be no resize optition, though)

Thanks

Here is the code:

/* Load admob ad, change ca-app-pub-****** */
        adView = new AdView(this, AdSize.IAB_BANNER,
                "ca-app-pub-*********");
        LinearLayout adLayout = (LinearLayout) findViewById(R.id.admob_banner);
        adLayout.addView(adView);
        if (isNetworkConnected()) {
            adView.loadAd(new AdRequest());
        }


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="5dp" >

        <Button
            android:id="@+id/answer3"
            style="@style/mText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="5dp"
            android:layout_weight="1"
            android:background="@drawable/orange_btns"
            android:shadowColor="#000"
            android:shadowDx="1.0"
            android:shadowDy="1.0"
            android:shadowRadius="0.7"
            android:text="Word 3"
            android:textColor="#333333"
            android:textStyle="bold" />

        <Button
            android:id="@+id/answer4"
            style="@style/mText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="10dp"
            android:layout_weight="1"
            android:background="@drawable/orange_btns"
            android:shadowColor="#000"
            android:shadowDx="1.0"
            android:shadowDy="1.0"
            android:shadowRadius="0.7"
            android:text="Word 4"
            android:textColor="#333333"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/admob_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginTop="10dp"
        android:gravity="bottom"
        android:minHeight="60dp"
        android:orientation="vertical" >

    </LinearLayout>
</LinearLayout>
Was it helpful?

Solution

You can dynamically load adsize based on screen resolution:

      AdSize adSize = AdSize.SMART_BANNER;

        DisplayMetrics dm = getResources().getDisplayMetrics();

        double density = dm.density * 160;
        double x = Math.pow(dm.widthPixels / density, 2);
        double y = Math.pow(dm.heightPixels / density, 2);
        double screenInches = Math.sqrt(x + y);

        if (screenInches > 8) { // > 728 X 90
            adSize = AdSize.LEADERBOARD;
        } else if (screenInches > 6) { // > 468 X 60
            adSize = AdSize.MEDIUM_RECTANGLE;
        } else { // > 320 X 50
            adSize = AdSize.BANNER;
        }



// Create an ad.
        adView = new AdView(this);
        adView.setAdSize(adSize);
        adView.setAdUnitId(AD_UNIT_ID);

OTHER TIPS

just changed the adView = new AdView(this, AdSize.IAB_BANNER, "ca-app-pub-*****") to adView = new AdView(this, AdSize.BANNER, "ca-app-pub-*****");

problem solved. Thanks

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