如何覆盖onSetContentView而在Andengine基本游戏活动使用比例分辨率政策 [英] How to override onSetContentView while Using Ratio Resolution policy in Andengine Base game activity

查看:144
本文介绍了如何覆盖onSetContentView而在Andengine基本游戏活动使用比例分辨率政策的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发(学习打造:))一个游戏andengine GLES2。 我使用的基本游戏活动,然后我将覆盖setContent认为把我的AdMob的广告。
每一件事情能正常工作,除了解决策略。
比解决策略是我使用连同 CAMERA_WIDTH = 800一;和CAMERA_HEIGHT = 480;

I am developing (Learning to build :) ) a game with andengine GLES2. I am using Base game activity , and i overrides the setContent view to place my admob ad.
Every thing works fine except the resolution policy .
Ratio Resolution policy is the one I am using along with CAMERA_WIDTH = 800; and CAMERA_HEIGHT = 480;

问题是,每当overided onsetContentView 现场未得到对准中心 利润率仅在底部显示不是顶部和底部上,同样会造成当水平对齐缘将只在右侧被显示,而不是在两侧上。我该如何纠正这一问题。我给我的code以下

The issue is whenever overided onsetContentView scene is not get aligned to center ,margins displayed only on bottom not on both top and bottom, Same will cause when horizontally align the margin will be displayed only at right side, not on both sides. how can i correct this. I am giving my code below

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

}

下面是图片是我让你可以看到白边下方的场景,如果你选择的图像(它不进入,由于堆栈溢出也有白色背景的关注)

here is the image what i get you can see the white margin below the scene if you select the image ( its not get into attention due to stack overflow also had white background )

任何建议,将十分有助于全面给我

any suggestions will be very help full to me

我怎样才能解决这个Isuue请帮我

How Can i solve this Isuue Please help me

感谢所有,

推荐答案

固定:

在进行游戏我能够解决这个问题的布局。

After a game with the layouts I am able to fix this.

现在我的面观统领对准中心和广告显示以预期的方式。

Now my surface view get aligned to center and the ad displays in a desired way.

下面是我的code

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



}

这篇关于如何覆盖onSetContentView而在Andengine基本游戏活动使用比例分辨率政策的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆