我尝试在游戏中展示广告。 这是我用来做的一种方法:
@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的解决方案政策?
答案 0 :(得分:0)
好的,所以答案很简单......只需要设置引力。:
<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>