问题
I want to add the Admob / AdWhirl into the GameLayer Scene.
I search over everywhere but couldn't find the way to do this work. I don't want to switch the Library. So , what should i do?
If someone have worked on it , give some way to do this .
回答1:
as there is not layout xml file for cocos2d android you can add it progammatically. crate linear layout in onstart method itself.
like this
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
adView = new AdView(SimpleGame.this, AdSize.BANNER, "your Ad ID");
adView.setAdListener(SimpleGame.this);
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(request);
CCDirector.sharedDirector().getActivity().addContentView(adView,adParams);
this should be in try and catch.
回答2:
of course we can add admob and or any other lib in your cocos2d games activity class.
You need to implement adlistener to your activity and add the adview in the OnStart() method of your game .
来源:https://stackoverflow.com/questions/17971120/can-we-use-googleads-admob-adwhirl-in-cocos2d-android