2011-11-16 81 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>