【发布时间】:2013-07-29 14:20:41
【问题描述】:
Admob 广告未显示在我的应用程序中。我感觉到广告正在加载,但由于我的布局安排,它没有显示。但我找不到它。这是我的代码
protected void onSetContentView() {
final RelativeLayout relativeLayout = new RelativeLayout(this);
final FrameLayout.LayoutParams relativeLayoutLayoutParams = new FrameLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT, RelativeLayout.LayoutParams.FILL_PARENT);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);
final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(layoutParams);
surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
FrameLayout frameLayout = new FrameLayout(this);
adView = new AdView(this, AdSize.BANNER, "##############");
adView.refreshDrawableState();
adView.setVisibility(AdView.VISIBLE);
frameLayout.addView(adView);
relativeLayout.addView(frameLayout);
this.setContentView(relativeLayout, relativeLayoutLayoutParams);
}
【问题讨论】:
-
您是否考虑过从 xml 而不是从代码构建布局?试试这个
-
我正在使用 andengine 这就是为什么我不能使用 xml 来执行此操作。在andengine中有什么办法吗
-
您可以使用andengine 在XML 中执行此操作。查看 andengine 示例。有一个演示如何做到这一点。 code.google.com/p/andengineexamples/source/browse/src/org/…
-
@PlasticSturgeon 感谢您的链接。我会看一看。但是你能告诉我为什么我的代码没有显示 admob 广告吗?
-
威廉,在下面,也打败了我吧。您的相对布局占据了整个屏幕 (FILL_PARENT),因此框架布局被压扁在下方。使用 XML,您无需编译就可以看到这一点。
标签: java android admob andengine