我想覆蓋2個視圖。以編程方式覆蓋視圖RelativeLayout
我的AdView應該在我的GameView上方「浮動」。
RelativeLayout layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
layout.setLayoutParams(params);
AdView admobView = createAdView();
layout.addView(admobView);
View gameView = createGameView(config);
layout.addView(gameView);
setContentView(layout);
startAdvertising(admobView);
private AdView createAdView() {
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID);
adView.setId(R.id.classic); // this is an arbitrary id, allows for relative positioning in createGameView()
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(params);
adView.setBackgroundColor(Color.TRANSPARENT);
return adView;
}
private View createGameView(AndroidApplicationConfiguration cfg) {
gameView = initializeForView(new MyGdxGame(), cfg);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
params.addRule(RelativeLayout.BELOW, adView.getId());
gameView.setLayoutParams(params);
return gameView;
}
這隻會將遊戲視圖設置在adview下面。
謝謝
編輯:太多的代碼......
那麼你的問題是什麼?你在問題結束時說過'這隻會將遊戲視圖設置在adview'下面' – 2014-08-29 14:15:41
希望這張圖片能夠描述我想要做的事情。我想要GameView內的AdView。 http://s1.directupload.net/images/140829/w3nkbf2s.jpg – KennyPew 2014-08-29 14:35:24