如何将广告置于屏幕底部中央(libgdx + AdMob)

时间:2013-08-02 22:53:29

标签: android android-layout admob libgdx

我正在使用libgdx和AdMob。我无法将广告置于屏幕底部的中心位置。在当前的设置中,我将它放在屏幕的左下角,但它不会居中。

我的MainActivity中的代码

 // Add the AdMob view
    RelativeLayout.LayoutParams adParams = 
            new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                            RelativeLayout.LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    adParams.addRule(RelativeLayout.CENTER_IN_PARENT);

    layout.addView(adView, adParams);

2 个答案:

答案 0 :(得分:8)

我是愚蠢的。我使用的代码已经正确,但我需要删除左对齐。我猜是打电话给左边,然后把电话对中,之后就没有坚持。

// Add the AdMob view
RelativeLayout.LayoutParams adParams = 
        new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                        RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
//adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
adParams.addRule(RelativeLayout.CENTER_IN_PARENT);

layout.addView(adView, adParams);

这很有效。

答案 1 :(得分:0)

for libgdx将此代码粘贴到onCreate()

中的ur android类中

layout = new RelativeLayout(this);     adView =新AdView(此广告,AdSize.BANNER,adMObid);

View gameView=initializeForView(new TalkingFriendApp(this), cfg);

RelativeLayout.LayoutParams adParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

RelativeLayout.LayoutParams adParams1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
adParams1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adParams1.addRule(RelativeLayout.ALIGN_PARENT_CENTER);

adView.loadAd(new AdRequest());

layout.addView(gameView, adParams);
layout.addView(adView, adParams1);

setContentView(layout);