问题在于,在540x960(我的手机)分辨率下,广告效果很好,但在其他分辨率上却没有。这是一个错误:“没有足够的空间来展示广告”。我认为布局可能有问题,但我不知道是什么。
我的主要活动:
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
//initialize(new JumpJackieJump(this), cfg);
this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
//setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
RelativeLayout layout = new RelativeLayout(this);
requestWindowFeature(Window.FEATURE_NO_TITLE); //no title is needed
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
adView = new AdView(this);
adView.setAdUnitId(ADCODE);
adView.setAdSize(AdSize.SMART_BANNER);
ad = new InterstitialAd(this);
ad.setAdUnitId(FULLADCODE);
View gameView = initializeForView(new JumpJackieJump(new RequestHandler(adView, ad), this), cfg);
AdRequest adRequest = new AdRequest.Builder().build();
AdRequest fadReq = new AdRequest.Builder().build();
adView.loadAd(adRequest);
ad.loadAd(fadReq);
layout.setPadding(0, 0, 0, 0);
layout.addView(gameView);
RelativeLayout.LayoutParams adParams =
new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(adView, adParams);
setContentView(layout);
if (!ad.isLoaded())
ad.loadAd(fadReq);
ad.setAdListener(new AdListener()
{
@Override
public void onAdClosed()
{
AdRequest fadReq = new AdRequest.Builder().build();
ad.loadAd(fadReq);
}
});
答案 0 :(得分:0)
您可以根据设备的屏幕分辨率动态加载广告:
AdSize adSize = AdSize.SMART_BANNER;
DisplayMetrics dm = getResources().getDisplayMetrics();
double density = dm.density * 160;
double x = Math.pow(dm.widthPixels / density, 2);
double y = Math.pow(dm.heightPixels / density, 2);
double screenInches = Math.sqrt(x + y);
if (screenInches > 8) { // > 728 X 90
adSize = AdSize.LEADERBOARD;
} else if (screenInches > 6) { // > 468 X 60
adSize = AdSize.MEDIUM_RECTANGLE;
} else { // > 320 X 50
adSize = AdSize.BANNER;
}
adView = new AdView(this);
adView.setAdUnitId(FULLADCODE);
adView.setAdSize(adSize);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);