简体   繁体   中英

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>

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM