I need to add an admob adview to a linear layout in code but I need to insert it at the top of the layout, not the bottom.
Is there a way to do this?
I was trying to do it as well, but using only LinearLayout
it always added the view at the bottom, no matter which index
I passed to addView
.
I wrapped the LinearLayout
in a RelativeLayout
, then you do that:
relativeLayout.addView(adView);
adView.setId(View.generateViewId());
RelativeLayout.LayoutParams llParams = (RelativeLayout.LayoutParams)linearLayout.getLayoutParams();
llParams.addRule(RelativeLayout.BELOW, adView.getId());
That is working for me.