Reputation: 465
I have designed a game with no xml layouts.I have used my own view extending the SurfaceView class .This is the code i am using.
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_ad=new AdView(this,AdSize.BANNER,"################");
rl.addView(myView);
rl.addView(_ad);
_ad.loadAd(new AdRequest());
setContentView(rl);
myView is the instance of class extending SurfaceView and _ad is the AdView instance.
I want to show the the ads at the bottom of the screen.But they are getting displayed only at the top.
Please suggest me what to do.I will be very grateful.
Upvotes: 0
Views: 1987
Reputation: 465
The only mistake I was doing was not associating my LayoutParams lay variable with the _ad AdView instance.So here is the code after modification.
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lay = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lay.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
_ad=new AdView(this,AdSize.BANNER,"################");
rl.addView(myView);
rl.addView(_ad,lay); //line which was changed.Everything else was correct
_ad.loadAd(new AdRequest());
setContentView(rl);
Thank You StackOverflow.
Upvotes: 0