Android CropResolutionPolicy和AdMob在andEngine中不合作

Android CropResolutionPolicy和AdMob在andEngine中不合作,android,admob,andengine,screen-resolution,Android,Admob,Andengine,Screen Resolution,我尝试在我的游戏中显示广告。 以下是我用来实现这一目标的方法: @Override public void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); //public void onSetContentView(){ //super.onSetContentView(); setContentView(R.layout.activity_main); th

我尝试在我的游戏中显示广告。 以下是我用来实现这一目标的方法:

@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);

//public void onSetContentView(){

    //super.onSetContentView();
    setContentView(R.layout.activity_main);

    this.adView = new AdView(this);
    this.adView.setAdSize(com.google.android.gms.ads.AdSize.SMART_BANNER);
    this.adView.setY(50);

    this.adView.setAdUnitId("here goes my id");

    com.google.android.gms.ads.AdRequest adrequest = new com.google.android.gms.ads.AdRequest.Builder().addTestDevice(com.google.android.gms.ads.AdRequest.DEVICE_ID_EMULATOR).build();

    this.adView.loadAd(adrequest);

    RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);



    layout.addView(this.mRenderSurfaceView);
    layout.addView(this.adView, params);



}
和XML布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id ="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"

tools:context="com.hsdev.salesrep.MainActivity" >

没有布局和临时解决方案,政策效果很好。但在添加布局后,它有点拉伸。另外,当我试图将其更改为RatioResolutionPolicy时,它在水平视图中被对齐到左侧,边缘仅在右侧,而不是像安第斯山脉通常那样在两侧。所以问题是:我如何使用布局,因为我想显示广告,但仍然使用andEngine的解析策略?

好的,所以答案很简单……只需要设置重力:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id ="@+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
tools:context="com.hsdev.salesrep.MainActivity" >
</RelativeLayout>