开发者

Android LayoutParams Problem - View always up top

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, LayoutPar开发者_高级运维ams.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.


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.


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜