0

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
kstrat2001
  • 21
  • 1
  • 5

2 Answers2

2

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.

kstrat2001
  • 21
  • 1
  • 5
-2

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?

Abhishek Susarla
  • 578
  • 1
  • 6
  • 12
  • I have to programmatically add the view because I had no luck using XML since the main Activity view is an OpenGL view. It didn't seem like there was a way to overlay an XML defined view on the GL view. The code above is in onStart() in the initial Activity. I have also tried putting the code in other places such as onEnter() above and below the GL view creation. I have also tried defining it in xml but get a force close because I can't load the view into the GL view activity. I can post more code when I get home today and also try the suggested AbsoluteLayout. I haven't tried that yet. – kstrat2001 Jan 31 '11 at 22:18