tonyw
May 9, 2017, 2:58pm
#1
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
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.
After many failed tries I managed to position admob view at bottom.
You need to edit Cocos2dxActivity.java in libcocos2dx.
1.Add a new static member after private static Context sContext = null; :
public static FrameLayout framelayout;
2.In public void init() method change FrameLayout framelayout = new FrameLayout(this);
to framelayout = new FrameLayout(this);
In your AppActivity.java where you want to initialize admob use this:
` adView = new AdView(this);
adView.setAdSize(AdSize.B…
Regards,
Gurudath
1 Like
tonyw
May 10, 2017, 8:59am
#3
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.
tonyw
May 10, 2017, 9:42am
#5
thanks again!
I’m wondering what/where AdView is? Is that an adroid thing, or a MoPub object?
Gurudath:
new AdView(this);
@tonyw ,
Are you able to import
import com.mopub.mobileads.AdView; ?
1 Like
tonyw
May 10, 2017, 11:24am
#7
aha, that answers my question thanks
tonyw
June 11, 2017, 9:30am
#8
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