我想在我的
Android游戏中添加MoPub广告.游戏是在SurfaceView Class上创建的.我没有xml布局文件.问题是我无法将广告置于屏幕上.我尝试中心和重力一切.仍然无法正常工作. MoPubView扩展了FrameLayout.
MoPubView mAdView = new MoPubView(this);
mAdView.setAdUnitId("_MY__ID_");
mAdView.loadAd();
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
RelativeLayout mRelativeLayout = new RelativeLayout(this);
mRelativeLayout.setGravity(Gravity.CENTER_HORIZONTAL);
mRelativeLayout.addView(mSurface);
mRelativeLayout.addView(mAdView, layoutParams);
mRelativeLayout.invalidate();
setContentView(mRelativeLayout);
请告诉我一些事情,因为它让我抓狂.我觉得我很遗憾.
最佳答案 你不能直接将内容集中在MoPub中,或者至少我还没有找到办法.它基于FrameLayout.
您必须将广告置于HTML中心.如果您在MoPub广告系列中使用自定义HTML代码,只需将代码包装在< div style =“text-align:center”> …< / div>内. (通过MoPub管理网站执行此操作).它解决了我的问题,我使用的是OpenX广告提供商.