Search code examples
androidlayoutadmobadview

Android replace an existing view with an admob ad


I'm implementing ads in my android app. They work fine, but it takes them a few seconds to pop up which then resizes my layout elements. I want to have the layout elements pre-resized even before the ad is loaded so they don't shift once it is.

Is there any way to replace an existing view (taking up the space where the ad would go) with the ad view once it's loaded? Any other way to get the same effect?

Thanks

(Also, I'm adding the ad view programmatically, not through XML, though I could change that if need be)


Solution

  • What I ended up doing is setting the adView's minimum height equal to 50 pixels multiplied times the density factor (1.5 for high, 1 for medium, .75 for low) since those values correspond to the ad height for banners. Works perfectly.