gpt4 book ai didi

android - 如何在 Andengine Base 游戏 Activity 中使用 Ratio Resolution 策略时覆盖 onSetContentView

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:09:05 26 4
gpt4 key购买 nike

我正在使用 andengine GLES2 开发(学习构建 :) 游戏。我正在使用 Base game activity,我覆盖了 setContent View 来放置我的 admob 广告。
除解析策略外,一切正常。
< strong>Ratio Resolution policy 是我与 CAMERA_WIDTH = 800; 一起使用的策略;和 CAMERA_HEIGHT = 480;

问题是,无论何时被覆盖,onsetContentView 场景都不会与中心对齐,并且边距仅显示在底部而不是同时显示在顶部和底部。水平对齐时也会发生同样的情况:边距将只显示在右侧,而不是两侧。我该如何纠正这个问题?我在下面给出我的代码:

@Override
protected void onSetContentView() {

System.out.println("Content setting");
this.mRenderSurfaceView = new RenderSurfaceView(this);


final LayoutParams layoutParams = new LayoutParams(
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
android.view.ViewGroup.LayoutParams.MATCH_PARENT);

layoutParams.gravity = Gravity.LEFT ;

final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(
layoutParams);

adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxx");

final FrameLayout.LayoutParams adViewLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.WRAP_CONTENT,
FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.LEFT
);

final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.FILL_PARENT,
FrameLayout.LayoutParams.FILL_PARENT,Gravity.CENTER);

frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
frameLayout.addView(adView, adViewLayoutParams);


this.setContentView(frameLayout, frameLayoutLayoutParams);
this.mRenderSurfaceView.setRenderer(this.mEngine, this);

}

这是我得到的图像,如果您选择该图像,您可以看到场景下方的白色边缘(由于堆栈溢出也没有引起注意,它也有白色背景)

enter image description here

任何建议都会对我很有帮助

我该如何解决这个问题请帮助我

感谢大家

最佳答案

已修复:

在使用布局进行游戏后,我可以解决这个问题。

现在我的表面 View 与中心对齐并且广告以所需的方式显示。

这是我的代码

@Override
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);
this.mRenderSurfaceView.setRenderer(this.mEngine, this);


final android.widget.RelativeLayout.LayoutParams surfaceViewLayoutParams = new RelativeLayout.LayoutParams(BaseGameActivity.createSurfaceViewLayoutParams());
surfaceViewLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);

relativeLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);


FrameLayout frameLayout = new FrameLayout(this);
adView = new AdView(this, AdSize.BANNER, "xxxxxxx");
adView.refreshDrawableState();
frameLayout.addView(adView);
relativeLayout.addView(frameLayout);

this.setContentView(relativeLayout, relativeLayoutLayoutParams);



}

关于android - 如何在 Andengine Base 游戏 Activity 中使用 Ratio Resolution 策略时覆盖 onSetContentView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14427152/

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