【问题标题】:CropResolutionPolicy and AdMob in andEngine not working togetherandEngine 中的 CropResolutionPolicy 和 AdMob 无法协同工作
【发布时间】:2015-03-28 17:46:13
【问题描述】:

我尝试在我的游戏中展示广告。 这是我用来执行此操作的方法:

@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 中那样在两者上)。所以问题是:我如何使用布局(因为我想展示广告,并且仍然使用 andEngine 的解析策略?

【问题讨论】:

    标签: android admob andengine screen-resolution


    【解决方案1】:

    好的,答案很简单……只需要设置重力即可。:

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

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 2015-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-24
      • 1970-01-01
      相关资源
      最近更新 更多