Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8231503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:31:02+00:00 2026-06-07T17:31:02+00:00

I have tried to change AdMob orientation in Libgdx, when the user reach a

  • 0

I have tried to change AdMob orientation in Libgdx, when the user reach a screen. I want to put it to the bottom of the screen. I have made a handler, implement it on the appropriate screens, and then call the method, by

myHandler.moveAds(true);

My interface looks like this:

public interface IActivityRequestHandler {
    public void showAds(boolean show);
    public void moveAds(boolean move);
}

The Android project file looks like this:

public class MyAndroidnewActivity extends AndroidApplication implements IActivityRequestHandler {
     protected AdView adView;
     RelativeLayout.LayoutParams adParams;

     private final int SHOW_ADS = 1;
     private final int HIDE_ADS = 0;
     private final int MOVE_ADS = 1;
     private final int PLACE_ADS = 0;

     protected Handler handler = new Handler()
     {
         @Override
         public void handleMessage(Message msg) {
             switch(msg.what) {
                 case SHOW_ADS:
                 {
                     adView.setVisibility(View.VISIBLE);
                     break;
                 }
                 case HIDE_ADS:
                 {
                     adView.setVisibility(View.GONE);
                     break;
                 }
             }
         }
     };

     protected Handler moveHandler = new Handler()
     {
         @Override
         public void handleMessage(Message msg) {
             switch(msg.what) {
                 case MOVE_ADS:
                 {
                    //In my opinion this code is not good, because It doesn't do anything 
                    //when I call the myHandler.moveAds(true); in an another class      
                    adView.setGravity(Gravity.BOTTOM);
                     break;
                 }
                 case PLACE_ADS:
                 {
                    adView.setGravity(Gravity.TOP);
                     break;
                 }
             }
         }
     };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
        cfg.useGL20 = false;
        cfg.useAccelerometer = false;
        cfg.useCompass = false;


            // Create the layout
            RelativeLayout layout = new RelativeLayout(this);

            // Do the stuff that initialize() would do for you
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
                            WindowManager.LayoutParams.FLAG_FULLSCREEN);
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

            // Create the libgdx View
            View gameView = initializeForView(new MyApp(this), false);

            // Create and setup the AdMob view
            adView = new AdView(this, AdSize.BANNER, "MYOWNKEY"); // Put in your secret key here
            AdRequest re = new AdRequest();
            re.addTestDevice("MYOWNDEVICECODE");
            adView.loadAd(re);

            // Add the libgdx view
            layout.addView(gameView);

            // Add the AdMob view
            adParams = 
                    new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            adParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
            adParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

            layout.addView(adView, adParams);

            // Hook it all up
            setContentView(layout);
        }


        @Override
        public void showAds(boolean show) {
           handler.sendEmptyMessage(show ? SHOW_ADS : HIDE_ADS);
        }

        @Override
        public void moveAds(boolean move) {
           moveHandler.sendEmptyMessage(move ? MOVE_ADS : PLACE_ADS);
        }
    }

But when I call the myHandler.moveAds(true); method in an another class, it doesn’t do anything, no errors, just the ad on the top of the (landscape) screen, and not on the bottom.

In my opinion there is a problem with my

  protected Handler moveHandler = new Handler()
     {
         @Override
         public void handleMessage(Message msg) {
             switch(msg.what) {
                 case MOVE_ADS:
                 {
                    //In my opinion this code is not good, because It doesn't do anything 
                    //when I call the myHandler.moveAds(true); in an another class      
                    adView.setGravity(Gravity.BOTTOM);
                     break;
                 }
                 case PLACE_ADS:
                 {
                    adView.setGravity(Gravity.TOP);
                     break;
                 }
             }
         }
     };

code. Maybe I need to control the orientation in an another way, but I don’t know how. Thanks in advance for any helps!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T17:31:04+00:00Added an answer on June 7, 2026 at 5:31 pm

    The setGravity() method determines where to place the content (in this case the ad) within the AdView, not where to place the AdView inside it’s container.

    It looks like you’re container is a RelativeLayout, so you should be able to just set new LayoutParams instead of setting the gravity:

    RelativeLayout.LayoutParams adParams =
        new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
                                        RelativeLayout.LayoutParams.WRAP_CONTENT);
    adParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); // or RelativeLayout.ALIGN_PARENT_TOP
    adView.setLayoutParams(adParams);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have links like these that I want to change: mypage.com?page=missions&id=5 mypage.com?page=hello I tried
I am using Eclipse 3.4.1 Build M20080911-1700 I have tried to change the classpath
Anything I have tried didn't work. Currenly I have following code to change asp.net
How to change cell background image on click on cell in iphone????I have tried
My code gives the above error. I have tried to change it based on
I have a double values in C# and I want to put them into
I have tried to change file association of .htm file in XP, and here
How can I compare the bootlean to a string? I have tried to change
have tried to change the timezon in android-emulator but it doesn't work. I write
I have tried to change magento order items quantity, but It doesn't work. Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.