Creating a layout.xml for ad networks

hi,

Trying to get mopub ads working on my cocos2d-x android app. Now, they tell me to add stuff to my app’s layout.xml file, but as we know, cocos doesn’t use this way of working, and the file doesn’t need to exist.

So the question is, what to do? Maybe I can just create a layout file, or do it programatically somehow? I’m no android expert, so this is wild west territory for me :slight_smile:

any thoughts?

tony

@tonyw,

Do you want to create Relative Layout to display Banner Ads either Top/Bottom of the Screen?

If yes, below link might help full for you.

Regards,
Gurudath

1 Like

Yes, top or bottom. But, admob I can do, mopub is proving more of a problem!

Hi @tonyw ,

I was looking at this documentation.

Define a slot for your banner ad in your layout XML

<com.mopub.mobileads.MoPubView
android:id="@+id/adview"
android:layout_width=“fill_parent”
android:layout_height=“50dp”
/>

Instead of above one, You can try with

AdView mAdView = new AdView(this);
RelativeLayout relativeLayout = new RelativeLayout(AppActivity.getInstanceActivity());
FrameLayout.addView(relativeLayout);

RelativeLayout.LayoutParams adViewParams = new RelativeLayout.LayoutParams(
	AdView.LayoutParams.WRAP_CONTENT,
	AdView.LayoutParams.WRAP_CONTENT);

adViewParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
relativeLayout.addView(mAdView, adViewParams);

Load an ad into the banner slot

moPubView = (MoPubView)mAdView;
moPubView.setAdSize(AdSize.BANNER);
moPubView.setAdUnitId("xxxxxxxxxxx");
moPubView.loadAd();

I haven’t tried this code. Hope it may work.

thanks again!

I’m wondering what/where AdView is? Is that an adroid thing, or a MoPub object?

@tonyw,

Are you able to import
import com.mopub.mobileads.AdView; ?

1 Like

aha, that answers my question :slight_smile: thanks

hi again,

Finally got to looking at this again. Actually, I find this does not exist -

import com.mopub.mobileads.AdView

Whereas I can do this -

import com.mopub.mobileads.*;
private MoPubView moPubView;

tony