2014-07-09 19 views
0

我試圖讓我的webview坐在我的Google Ad Mob廣告上方。但是,除非以編程方式嘗試和調整高度,否則Web視圖始終覆蓋整個屏幕。我試着將webview的高度設置爲屏幕高度減去我的廣告高度,但這似乎並不能在所有設備上準確地工作。如果我希望我的廣告坐在網頁視圖的下方,我的webview的高度應該設置爲多少?如何確保我的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> 
+0

因爲高度設置爲FILL_PARENT和廣告低於 – Decoy

+0

我試着將它設置爲剛纔的一切,我能明顯地將它設置爲500浸,但當然不會每個設備規模。 – Caimen

+0

只需在您的廣告視圖中移除layout_below並設置align_ParentBottom = true – Decoy

回答

0

我能夠使用線性佈局修復問題。這似乎是讓谷歌廣告羣發廣告在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> 
1

試試這個:

<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"/> 

添加視圖應該是web視圖和web視圖全屏以上。

+0

我將adView移到了webview上方並添加了alignParentBottom,但我仍然獲得覆蓋整個屏幕的webview。 – Caimen

+0

不,adview必須在webview下面聲明,這樣纔會在webview之上。 – Decoy

相關問題