title: Admob Banner on Top of layout
body: <p>I want to display banner on top of the screen, but there is a problem. In my code (this is not my code, because I`m in learning process) I have two options. To show banner under or over the screen on bottom of screen. </p>
  
  <pre><code>    public void showBanner(final boolean inLayout) {
      //banner ad
      if (BANNER_AD_UNIT_ID.length() &gt; 0) {
          // Create an ad.
          adView = new AdView(this);
          adView.setAdSize(AdSize.BANNER);
          adView.setAdUnitId(BANNER_AD_UNIT_ID);
  
          if (inLayout) {
              //make ad visible on bottom of screen over surface
              RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
              params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
              params1.addRule(RelativeLayout.CENTER_HORIZONTAL);
              adView.setLayoutParams(params1);
          } else {
              //make ad visible on bottom of screen under surface
              LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
              params.gravity = Gravity.BOTTOM;
              params.weight = 0;
              adView.setLayoutParams(params);
  
          }
  </code></pre>
  
  <p>If I change <code>params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);</code> from <code>BOTTOM</code> to <code>TOP</code>, banner is displayed over the screen on top. But if I change <code>params.gravity = Gravity.BOTTOM;</code> from <code>BOTTOM</code> to <code>TOP</code>, ad is still showed on the bottom :( </p>
  
  <p>Anyone can help me with this? Thanks so much!</p>
  
  <p>inLayout code:</p>
  
  <pre><code>// Start loading the ad in the background.
          adView.loadAd(adRequest);
          adView.setAdListener(new AdListener() {
              public void onAdLoaded() {
                  View parent = (View) adView.getParent();
                  if (parent != null) {
                      if (!(parent.equals(layout) || parent.equals(linear_layout))) {
                          if (inLayout)
                              layout.addView(adView);
                          else
                              linear_layout.addView(adView);
                          recalculateScreen();
                      }
                  } else {
                      //add new banner ad to screen
                      if (inLayout)
                          layout.addView(adView);
                      else
                          linear_layout.addView(adView);
                      recalculateScreen();
                  }
              }
          });
      }
  }
  
  //add relative layout to linear layout for banner ad mobility
      linear_layout = new LinearLayout(this);
      linear_layout.setOrientation(LinearLayout.VERTICAL);
      linear_layout.addView(layout);
  
      setContentView(linear_layout);
      holder = surface.getHolder();
  </code></pre>