TapForTap 的代码对于简单的 Android 应用来说看起来很简单:
setContentView(R.layout.main);
AdView adView = (AdView) findViewById(R.id.ad_view);
ad_view 在 XML 中定义:
<com.tapfortap.AdView android:id="@+id/ad_view"
android:layout_height="50dip"
android:layout_width="320dip"
android:layout_gravity="bottom"
/>
但我使用 Libgdx,我需要这样的东西:
RelativeLayout layout = new RelativeLayout(this);
View gameView = initializeForView(new MyGame(), false); //this runs Libgdx
MobclixAdView adView = new MobclixMMABannerXLAdView(this);
adView.getAd();
adView.setRefreshTime(30000);
RelativeLayout.LayoutParams adParams = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layout.addView(gameView);
layout.addView(adView, adParams);
setContentView(layout);
问题是 TapForTap 的 AdView 没有构造函数,所以不能写:
AdView adview=new AdView();
如果我做
layout.addView(adView);
我收到一个错误,adView 已经有父级。
有任何想法吗?谢谢!