20

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.

Jagjit Singh
  • 1,711
  • 11
  • 17
  • 2
    Did you found a solution? I'm interested too. – AlexioVay Jun 10 '16 at 17:28
  • 1
    @Vaia Not yet trying hard – Jagjit Singh Jun 13 '16 at 06:32
  • check http://stackoverflow.com/questions/16151526/how-to-get-admob-in-webview and http://stackoverflow.com/questions/25226698/how-to-use-admob-in-android-webview –  Oct 20 '16 at 07:49
  • You can arrange your `WebView content` and your native `AdView` 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 ;-) – longi Oct 07 '19 at 13:31

1 Answers1

1

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()

Link to documentation of translationY

Natig Babayev
  • 2,290
  • 9
  • 19
Qw4z1
  • 2,949
  • 1
  • 22
  • 35