在 SurfaceView 上居中 MoPub 横幅
我想在我的 Android 游戏中添加 MoPub 广告。游戏是在 SurfaceView 类上创建的。我没有 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);
请给我一些建议,因为它让我发疯。我觉得我错过了一些简单的事情。
I'd like add MoPub ad in my Android game. Game is created on SurfaceView Class. I have no xml layout file. The problem is that I can't center ad on screen. I try center and gravity everything. Still doesn't work. MoPubView extends 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);
Please advise me something because it drawing me crazy. I feel I'm missing something easy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您无法将内容直接集中在 MoPub 中,或者至少我还没有找到这样做的方法。它基于 FrameLayout。
您必须将 HTML 广告居中。如果您在 MoPub 活动中使用自定义 HTML 代码,只需将代码封装在
内即可。 (通过 MoPub 管理网络执行此操作)。它解决了我的问题,我正在使用 OpenX 广告提供商。
You can't center the content directly in MoPub, or at least I haven't found a way to do so. It's based on FrameLayout.
You have to center the ad in HTML. If you are using custom HTML code inside your MoPub campaign, just wrap the code inside
<div style="text-align:center">...</div>
. (Do this through the MoPub administration web). It solved my problem, I was using an OpenX ad provider.只需使用“FILL_PARENT”参数创建一个容器布局,然后将广告视图添加到其中,如下所示:
Just create a container layout with "FILL_PARENT" parameters and add your ad view into it like this:
我知道设置恒定的横幅宽度不是一个好主意,但只要您的横幅为 320 像素,它就可以正常工作:
I know it is not good idea to set constant banner width but as long as your banners are 320px it works fine:
我用下面的代码片段做了同样的事情。我正在使用 LibGDX java 游戏引擎。
1.我在父级中有相对布局。
2.在父相对布局中添加MoPubView,仅使用layoutParams ALIGN_PARENT_BOTTOM && CENTER_HORIZONTAL
I have done same thing with below code snippet.I am using LibGDX java game engine.
1.I have Relative layout in parent.
2.Added MoPubView in the parent Relative layout with layoutParams only ALIGN_PARENT_BOTTOM && CENTER_HORIZONTAL