gpt4 book ai didi

java - Admob 广告未在我的应用中显示

转载 作者:行者123 更新时间:2023-12-01 14:18:04 24 4
gpt4 key购买 nike

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);

}

最佳答案

您已将 SurfaceView 设置为 FILL_PARENT,因此它占用了所有空间,没有为 AdView 同级空间留下任何空间。

final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);

另请注意,无需使用 FrameLayout 来包装 AdView。

我建议您遵循 jquery404 的建议并在 XML 中定义布局。您将对您的用户界面设计有更好的了解。

关于java - Admob 广告未在我的应用中显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17926492/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com