2011-11-16 78 views
0

我第一次開發Android應用程序,到目前爲止,除了一件事情之外,它真的很好。我做了一個webview佈局,我想在應用程序中展示廣告。所以我添加了AdMob廣告,他們的工作非常好。但是有一個問題。與Admob和Webview重疊

AdMob覆蓋了WebView的一部分,因此它不會將WebView佈局向上移動,而是覆蓋它。這很煩人,因爲你無法閱讀webview文本的一部分。我該如何解決它?

這是我的main.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" android:id="@+id/rltvLayout01" 
    android:layout_height="fill_parent" android:background="@color/white"> 
    <ScrollView android:id="@+id/ScrollView01" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 
      <WebView android:id="@+id/webview" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:fitsSystemWindows="true" 
       android:scrollbars="none" /> 
    </ScrollView> 
    <LinearLayout android:id="@+id/ad_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="bottom" 
     android:layout_alignParentBottom="true"> 
      <com.google.ads.AdView android:id="@+id/ad" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       ads:adUnitId="helloworldcode" 
       ads:loadAdOnCreate="true" 
       ads:adSize="BANNER" /> 
    </LinearLayout> 
</RelativeLayout> 

我試着給了滾動的android:layout_above="@+id/ad_layout"但後來我的應用程序強制關閉......所以,我真的希望有人能幫助我,我要找的現在幾個小時:(

+0

歡迎來到Stackoverflow!如果您發現回覆有幫助,請投票。如果回覆成功回答您的問題,請點擊旁邊的綠色複選標記以接受答案。另請看看http://stackoverflow.com/questions/how-to-ask關於如何編寫一個好問題的建議 –

+0

你在logcat中獲得的堆棧跟蹤是什麼? –

回答

3

好像layout_above應該工作,但如果這是真的是你的完整佈局,在我看來,最簡單的辦法就是更換RelativeLayoutLinearLayout,因爲你只鋪設在這些視圖一條線,然後給主要部分的重量,我可能也會擺脫ScrollView,只是讓WebView滾動本身,但:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" android:id="@+id/rltvLayout01" 
    android:layout_height="fill_parent" android:background="@color/white" 
    android:orientation="vertical"> 
    <ScrollView android:id="@+id/ScrollView01" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_weight="1"> 
      <WebView android:id="@+id/webview" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:fitsSystemWindows="true" 
       android:scrollbars="none" /> 
    </ScrollView> 
    <com.google.ads.AdView android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adUnitId="helloworldcode" 
     ads:loadAdOnCreate="true" 
     ads:adSize="BANNER" /> 
</LinearLayout>