4

I'm using a plugin that creates another WebView (Appodeal banners) that overlaps the main apps WebView. Theres not a good way to fix that manipulating the HTML tags because elements mess

Default banner settings

32px : device screen height <= 400
50px : 400 < device screen height <= 720
90px = device screen height > 720

So the webview must resize height according to Appodeal banner height.

Example:

if (device.screen.height <= 400) { WebView.height = WebView.height - "32px" }

PS: I'm not Java programmer Web developer only

Rodolfo Paranhos
  • 793
  • 2
  • 7
  • 18
  • 1
    It is not really clear. You want to resize primary webview after a secondary webview (Appodeal) comes on top of it? If so, can't you catch event when the secondary view appears, get its size, and arrange the size of the primary webview to make it look like there is no display conflict? – nyluje Jun 02 '16 at 11:51
  • @nyluje Yes! You got it. – Rodolfo Paranhos Jun 02 '16 at 15:49
  • 1
    So you need to redefine the primary webview size in JAVA? It sounds that you need to build a plugin to modify the primary webview once the secondary webwiew appears. Have a look to this document: https://www.ibm.com/developerworks/community/blogs/worklight/entry/android_combining_native_and_web_controls_in_cordova_based_applications?lang=en – nyluje Jun 03 '16 at 07:29
  • Those information helped me, at the time, to understand how the different view layers (native and webview) worked. – nyluje Jun 03 '16 at 07:30
  • @nyluje Nice article! Actually all I need is the primary WebView height to be reduced in 32px 50px or 90x according to the device screen height. – Rodolfo Paranhos Jun 04 '16 at 04:31
  • @RodolfoParanhos I m not an android expert. But after some analysis, i found the following links useful. http://stackoverflow.com/questions/22878069/android-get-height-of-webview-content-once-rendered http://vision-apps.blogspot.in/2012/08/android-webview-tips-tricks.html https://capdroid.wordpress.com/2014/08/07/resizing-webview-to-match-the-content-size/ Hope it gives you a lead. – Gandhi Jun 04 '16 at 14:08

1 Answers1

2

I'm not sure you have to resize your root webview on Admob banner show (I'm not even sure it is possible at all). But all that you need to do is to re-layout content of your main webview when banner is shown. If I understood your post right, you use Appodeal PhoneGap Plugin that really uses one more webview component to show ads. In this case you know everything about:

  1. Banner placement (top or bottom), b/c you request it explicitly (Appodeal.BANNER_TOP | Appodeal.BANNER_BOTTOM);
  2. Banner size (you described it yourself in question);
  3. A fact that banner is appeared (document.addEventListener('onBannerShown', function(){...}););

So, I'd just prepare an empty placeholders in my HTML template, add CSS rules that will hide them when no Appodeal banner shown, and onBannerShown event will display corresponding placeholder and resize all my webview content.

<style>
  .appodeal-top {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 0;
  }
  .main-content {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
  }
  .appodeal-show .appodeal-top {
    /* replace it with appropriate value calculated on device height */
    height: 50px;
  }
  .appodeal-show .main-content {
    /* replace it with appropriate value calculated on device height */
    top: 50px;
  }
</style>
<script>
  document.addEventListener('onBannerShown', function(){
    document.getElementById('root').className = 'appodeal-show';
  });
</script>
<div id="root">
  <div class="appodeal-top"></div>
  <div class="main-content">
  ...
  </div>
</div>

(I didn't try this code - it just shows you an idea).

domax
  • 649
  • 3
  • 13
  • already made that way. this is not the purpose of the question but thank you anyway! – Rodolfo Paranhos Jun 09 '16 at 03:04
  • Yes, it is not, but I believe you cannot change size of root webview - just because Cordova has it as very top pane for application which dimensions are automatically set to screen size. – domax Jun 09 '16 at 03:18