I want to know how to show Native ad inside webview Content at random position everytime. Suppose i am loading static html page in webview. Is it possible to show native inside webview html page at random position when user reading the content of page native ads appear inside the content.
Showing Native Ads inside WebView content in Android?
Asked Answered
First of all, the title of your question is really misleading, since you are really asking about dynamic positioning of a view.
Second, what you want to do is shade AF and you will probably get a lot of negative reviews and quick uninstalls. =)
That being said, the answer to your question is yes.
The easiest way to achieve this is by setting the initial Y position of the webview to 0 (at the top of the screen) and then use View#setTranslationY
with a random value, which shifts the Y position. If you really want to annoy the users you can even animate it like this:
val random = Random()
val translation = random.nextInt(40)
webview.animate().translationYBy(translation.toFloat()).start()
© 2022 - 2024 — McMap. All rights reserved.
WebView content
and your nativeAdView
within your xml layout the way you want (top, bottom,left, above...). However, embedding your native Ads within your webview content sounds weird. I would suggest embedding your AdViews inside your webpage. Otherwise you'd need to manipulate your html-sources, which you don't want to do ;-) – Doubleheader