万普广告的AdView并不是继承于View,所以嵌入的方式有所不同。
一般广告签入传送门:《Android 游戏引擎libgdx 如何添加Admob、多盟类广告条》
万普广告: 传送门 (首先要自己去下载sdk和查看基本文档)
public class MainActivity extends AndroidApplication { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); init(); } private void init() { getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); getWindow().clearFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); RelativeLayout layout = new RelativeLayout(this); // add game view View gameView = initializeForView(new Game(), true); layout.addView(gameView); // init AD view new MyAd(this); layout.addView(MyAd.getAdView()); // add Content setContentView(layout); } }
public class MyAd { public static LinearLayout adLayout; public MyAd(Activity app) {
//定义视图容器 adLayout = new LinearLayout(app); LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); adLayout.setLayoutParams(adParams); adLayout.setGravity(Gravity.CENTER_HORIZONTAL);
//填写自己的APP_ID AppConnect.getInstance("WAPS_ID", "WAPS", app);
//这步是关键,传入容器的引用,进行广告的初始化,并且显示 new AdView(app, adLayout).DisplayAd(); } public static LinearLayout getAdView() { return adLayout; } }