Android LayoutParams 问题 - 视图始终位于顶部

发布于 2024-10-15 05:09:02 字数 651 浏览 4 评论 0原文

我正在尝试在 cocos2D 游戏中放置 mobclix 广告横幅。我的广告横幅显示在 openGL 视图的顶部。但是,我不知道如何将其放置在我们想要的屏幕底部。 mobclix 中的示例展示了将重力设置为底部的 LinearLayout 的使用。我在 GameActivity 中尝试了这一点,这是启动时的主要活动:

    adview_banner = new MobclixMMABannerXLAdView(this);
    adview_banner.addMobclixAdViewListener(this);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    params.gravity = Gravity.BOTTOM;

    this.addContentView(adview_banner, params);

    adview_banner.bringToFront();
    adview_banner.getAd();
    adview_banner.setRefreshTime(30000);

无论我在这里做什么,横幅总是显示在屏幕顶部。任何帮助将不胜感激。

I'm trying to put a mobclix ad banner in a cocos2D game. I have the ad banner showing up on top of the openGL view. However, I can not figure out how to place it at the bottom of the screen which is what we want. The example from mobclix shows the use of a LinearLayout with gravity set to bottom. I tried this in the GameActivity which is the main activity on startup:

    adview_banner = new MobclixMMABannerXLAdView(this);
    adview_banner.addMobclixAdViewListener(this);

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    params.gravity = Gravity.BOTTOM;

    this.addContentView(adview_banner, params);

    adview_banner.bringToFront();
    adview_banner.getAd();
    adview_banner.setRefreshTime(30000);

No matter what I do here the banner always shows up on the top of the screen. Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感性不性感 2024-10-22 05:09:02

好的!我想我终于拥有了!这些布局一开始在编程上很棘手,但它们确实与示例中的 xml 内容相匹配。我只需要将横幅嵌入到布局对象中并将其发送到该布局的底部。

在主要活动中:

    @Override
public void onStart() {
    super.onStart();

    RelativeLayout layout = new RelativeLayout(this);

    adview_banner = new MobclixMMABannerXLAdView(this);
    adview_banner.addMobclixAdViewListener(this);

    RelativeLayout.LayoutParams childParams = new RelativeLayout.LayoutParams(320, 50);
    childParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layout.addView(adview_banner, childParams);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    this.addContentView(layout, params);

    //adview_banner.bringToFront();
    adview_banner.getAd();
    adview_banner.setRefreshTime(30000);
}

现在唯一的问题是我在“webcore”的 Logcat 上收到“在第一个布局错误后无法获取 viewWidth”。广告横幅显示“发生错误。单击此处了解更多详细信息。”

我想我会就这一问题咨询 Mobclix 支持团队。

OK! I think I finally have it! Those layouts are tricky at first programmatically but they do match up with what the example had in the xml. I just needed to embed the banner in a layout object and send it to the bottom of that layout.

In the main Activity:

    @Override
public void onStart() {
    super.onStart();

    RelativeLayout layout = new RelativeLayout(this);

    adview_banner = new MobclixMMABannerXLAdView(this);
    adview_banner.addMobclixAdViewListener(this);

    RelativeLayout.LayoutParams childParams = new RelativeLayout.LayoutParams(320, 50);
    childParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layout.addView(adview_banner, childParams);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    this.addContentView(layout, params);

    //adview_banner.bringToFront();
    adview_banner.getAd();
    adview_banner.setRefreshTime(30000);
}

Now the only issue is that I get a "can't get the viewWidth after the first layout error" on the Logcat from "webcore". And the ad banner displays "An error has occurred. Click here for more details."

I think I'll consult the Mobclix support team on that one.

猫卆 2024-10-22 05:09:02

使用绝对布局。

    android:layout_width="40px"
    android:layout_marginRight="5px"
    android:layout_height="40px"

等等

线性布局只能为每个单独的子元素设置重力。

有用吗?

Use Absolute Layout.

    android:layout_width="40px"
    android:layout_marginRight="5px"
    android:layout_height="40px"

etc

Linear Layouts can only set gravities to each individual child.

Was it useful?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文