[英]how to change position of android banner app
我可以在我的libgdx android應用程序上添加橫幅廣告,但是我需要一些幫助來定位添加位置。 現在,如果我運行它,則橫幅廣告會顯示在頂部/中間,並將應用程序屏幕的其余部分向下移動。
如何更改它,以使橫幅廣告僅浮動在頂部/中央,而無需向下移動應用程序屏幕?
public class AndroidLauncher extends AndroidApplication {
// Ads
private static final String AD_UNIT_ID_BANNER = "ca-app-pub-222222222/111111";
private static final String GOOGLE_PLAY_URL = "https://play.google.com/store/apps/developer?id=testname";
protected AdView adView;
protected View gameView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
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);
//initialize(new MyGdxGame(), config);
}
private AdView createAdView() {
adView = new AdView(this);
adView.setAdSize(AdSize.SMART_BANNER);
adView.setAdUnitId(AD_UNIT_ID_BANNER);
adView.setId(12345); // this is an arbitrary id, allows for relative
// positioning in createGameView()
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
params.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
adView.setLayoutParams(params);
adView.setBackgroundColor(Color.BLACK);
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;
}
private void startAdvertising(AdView adView) {
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
}
如下所示,首先將視圖更改為adview,然后將adview更改為第二
View gameView = createGameView(config); layout.addView(gameView); AdView admobView = createAdView(); layout.addView(admobView);
並從createGameView函數中刪除或隱藏此行
params.addRule(RelativeLayout.BELOW, adView.getId());
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.