androidviewpanelmobclix

Integrating Ads in a Game


i have a 2D game which has my custom ViewPanel which handles all the drawings (i don't have android Button elements, all my game controls are painted/handled internally).

this is my main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
</LinearLayout>

and this is my activity's onCreate() main code:

    viewPanel = new ViewPanel(this);
    setContentView(viewPanel);

from this point my ViewPanel handles all the drawings/events.

Now, i want to integrate Ads (Mobclix), and this is how i do it:

    setContentView(R.layout.mobclix_advertising_view);
    Mobclix.onCreate(this);

    adview_banner = (MobclixMMABannerXLAdView) findViewById(R.id.advertising_banner_view);
    adview_banner.addMobclixAdViewListener(this);
    adview_banner.setRefreshTime(30000);
    adview_banner.getAd();

HOWEVER! it seems i can either setContentView on my ViewPanel OR on "advertising_banner_view" not both. So basically either i see my game drawing OR the advertising bar.

How can i see them both?


Solution

  • Try this:

    my_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent" android:layout_height="fill_parent">
    </FrameLayout>
    

    Now just use my_layout as you main layout, and call addView twice on it, once with your ViewPanel and once with your AdView. You can set the gravity of the adview to float it where ever you want on the screen.