Caimen
Caimen

Reputation: 2619

How do I make sure my webview can scale with devices?

I'm trying to get my webview to sit just above my Google Ad Mob ad. However the web view always covers the entire screen unless I programatically try and adjust the height. I've tried setting the height of the webview to the heigh of the screen subtracting my ad height, but that doesn't seem to work accurately on all devices. What should my height of my webview be set to if I want my ad to sit just below the webview?

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/linearLayout">

<WebView
    android:id="@+id/webView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="320dip"
android:layout_height="50dip"
ads:adUnitId="/serviceid/myadtagishere"
ads:adSize="BANNER"
android:layout_below="@+id/webView1"/>
</RelativeLayout>

Upvotes: 0

Views: 63

Answers (2)

Caimen
Caimen

Reputation: 2619

I was able to fix the problem using a linear layout. This seems to be the easiest and most effective way of getting a google ad mob ad to show up below a webview.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/linearLayout"
android:orientation="vertical">    

<WebView
    android:id="@+id/webView1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="50dip"
ads:adUnitId="/5773/sci.app.hoosierscoop"
ads:adSize="BANNER"/>
</LinearLayout>

Upvotes: 0

Decoy
Decoy

Reputation: 1597

Try this :

<com.google.android.gms.ads.AdView
  android:id="@+id/adView"
  android:layout_width="320dip"
  android:layout_height="50dip"
  ads:adUnitId="/serviceid/myadtagishere"
  ads:adSize="BANNER"
  android:layout_alignParentBottom="true"/>

The add view should be above the webview and the webview fullscreen.

Upvotes: 1

Related Questions