@adrian_dsl
Hi, can you explain where I must change FrameLayout framelayout = new FrameLayout(this);
to framelayout = new FrameLayout(this). I have no public void init() method in Cocos2dxActivity.java
If it’s possible, post here sample Cocos2dxActivity.java.
I’ve seen this before, but why do you set the background color to black, and then to 0?
Isn’t the black color line abundant now, as it’s overwritten immediately with 0?
After much trial and error, I’ve finally created a working version from all the advice above. I’ve pasted the full working method below (in AppActivity.java) to make it easier. I’m using Cocos2d-x v.3.2.
There’s 2 approaches you can take. Both require you to use mFrameLayout.addView() to explicitly add a LinearLayout or RelativeLayout. You don’t use addContentView(adView,adParams) as in the original sample at the AdMob tutorial.
— RelativeLayout.LayoutParams does not have a gravity property so you use addRule()
— LinearLayout.LayoutParams has a gravity property that you set with Gravity.BOTTOM.
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("B583486A9A64508744E7742E8CF3FC1F")
.build();
adView = new AdView(this);
// adView.setAdSize(AdSize.BANNER);
// SMART_BANNER spans the full width of the screen
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
adView.loadAd(adRequest);
adView.setBackgroundColor(Color.BLACK);
adView.setBackgroundColor(0);
// Option 1 using Relative Layout
// RelativeLayout relativeLayout=new RelativeLayout(this);
// RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams(
// AdView.LayoutParams.WRAP_CONTENT,
// AdView.LayoutParams.WRAP_CONTENT);
// relativeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//
// // nest the adView in the relativeLayout
// relativeLayout.addView( adView, relativeLayoutParams );
//
// mFrameLayout.addView( relativeLayout );
// Option 2 using Linear Layout with gravity
LinearLayout linearLayout = new LinearLayout( this );
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
adParams.gravity = Gravity.BOTTOM;
linearLayout.addView( adView, adParams );
mFrameLayout.addView( linearLayout );
// no longer use this to add the view. Instead we're adding the linearLayout explicitly above.
// addContentView(adView,adParams);