我试着在我的游戏中展示广告。下面是我用来做这个的一种方法:
@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的解析策略?)
发布于 2015-03-29 11:28:37
好的,答案是simple...Just需要设定重力。:
<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>https://stackoverflow.com/questions/29320482
复制相似问题