I have this in my main xml file:
For anyone interested here is a Kotlin version.
And inside the code behind
//create a new AdView
val adView = AdView(this)
adView.adSize = AdSize.SMART_BANNER
adView.adUnitId = "your adUnitID goes here or you can use a function"
adView.visibility = View.GONE
//add it to the layout
val layout = adContainer
layout.addView(adView)
//profit
MobileAds.initialize(this) {}
val adRequest = AdRequest.Builder().build()
adView.loadAd(adRequest)
adView.adListener = object : AdListener(){
override fun onAdLoaded() {
adView.visibility = View.VISIBLE
super.onAdLoaded()
}
}