2

我正在使用 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);
4

2 回答 2

7

我当时很傻。我使用的代码已经正确,但我需要删除左对齐。我猜想打电话给左然后居中,然后打电话没有坚持。

// 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);

这行得通。

于 2013-08-03T03:36:11.590 回答
0

对于 libgdx 将此代码粘贴到您的 android 类中的 onCreate()

布局 = 新的相对布局(这个);adView = new AdView(this, 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);
于 2013-08-03T02:50:05.750 回答