I'm using a FrameLayout to hold two views, one on top of the other. One is an AdView and the other is a SDLSurfaceView. Basically I want the AdView to be placed in front of the SDLSurfaceView but only when an actual Ad is being displayed. The ad loads after about 30 seconds after starting the app but if I click on where the ad should be when no ad is displayed, it still opens up a link. How do I keep the SDLSurfaceView in front of the AdView until the AdView actually loads?
Here is a sample of what I have so far:
mView = new SDLSurfaceView(
this,
mPath.getAbsolutePath());
Hardware.view = mView;
//CREATE WIDGETS LAYOUT PARAMETERS
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT,
Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL);
//CREATE ADVIEW
adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
adView.setAdSize(AdSize.BANNER);
//ADD LAYOUT PARAMETER TO ADVIEW
adView.setLayoutParams(lp);
//SET AD LISTENER
adView.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
super.onAdLoaded();
adView.bringToFront();
adView.invalidate();
mView.invalidate();
}
@Override
public void onAdFailedToLoad(int errorCode) {
super.onAdFailedToLoad(errorCode);
adView.getParent().bringChildToFront(mView);
mView.invalidate();
adView.invalidate();
}
});
//CREATE LAYOUT
FrameLayout layout = new FrameLayout(this);
//SET CONTENT TO LAYOUT
setContentView(layout);
//ADD VIEWS TO LAYOUT
layout.addView(adView);
layout.addView(mView);
//BUILD AD REQUEST
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.build();
adView.loadAd(adRequest);
I am using kivy to create an adroid app and python-for-android to package the apk. The sample is part of my PythonActivity.java used by the python-for-android packager.
0 comments:
Post a Comment