14

How to center the ad at the bottom of the screen (libgdx + AdMob)

 3 years ago
source link: https://www.codesd.com/item/how-to-center-the-ad-at-the-bottom-of-the-screen-libgdx-admob.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

How to center the ad at the bottom of the screen (libgdx + AdMob)

advertisements

I am using libgdx and AdMob. I am having trouble getting the ad to center in the bottom of the screen. In the current setup, I have it in the bottom left corner of the screen, but it will not center.

Code in my 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);


I was being dumb. The code I was using was already correct, but I needed to remove the align left. I guess calling left and then center the call afterward didn't stick.

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

This works.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK