Vins
Vins

Reputation: 4119

Ad is not coming at bottom

i have a problem regarding alignment of ad. The ad is coming at top of the app but i need it at the bottom of the app. I didnt defined any layout for ad just directly tried in java. And its working fine but only thing is its coming at top even after i inserted adView.setGravity(Gravity.BOTTOM); The code goes as below // Lookup R.layout.main

    RelativeLayout layout = (RelativeLayout)findViewById(R.id.relativeLayout);


    // Create the adView
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID
    AdView adView = new AdView(this, AdSize.BANNER, "a14e36b9902bfcc");

    // Add the adView to it
    layout.addView(adView);



    // Initiate a generic request to load it with an ad
    AdRequest request = new AdRequest();
    request.setTesting(true);

    adView.loadAd(request);  
    adView.setGravity(Gravity.BOTTOM);

Upvotes: 0

Views: 722

Answers (2)

Sherif elKhatib
Sherif elKhatib

Reputation: 45942

Specify the parameters when you add the view to the relative layout

Change

    // Add the adView to it
    layout.addView(adView);

to

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE); 
    layout.addView(adView,params);

Upvotes: 1

Ovidiu Latcu
Ovidiu Latcu

Reputation: 72311

You need to set the LayoutParams of your RelativeLayout to :

   RelativeLayout.LayoutParams params=
       new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,
                                       RelativeLayout.LayoutParams.FILL_PARENT);

Upvotes: 2

Related Questions