android - 与 Admob 和 Webview 重叠

标签 android xml webview admob

这是我第一次开发 Android 应用程序,到目前为止,除了一件事外,一切进展顺利。我做了一个 webview 布局,我想在应用程序中展示广告。所以我添加了 AdMob 广告,效果非常好。但是有一个问题。

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>

我试图给 ScrollView 一个 android:layout_above="@+id/ad_layout" 但后来我的应用程序强制关闭......所以我真的希望有人能帮助我,因为我正在寻找现在几个小时:(

最佳答案

看起来 layout_above 应该可以工作,但如果这真的是您的完整布局,我认为最简单的方法是用 LinearLayout 替换 RelativeLayout 因为无论如何您只是将这些 View 排成一行,然后给主要部分赋予权重。我可能还会摆脱 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>

关于android - 与 Admob 和 Webview 重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8154981/

相关文章:

android - 在 WebView 中启用长按

android - 我们可以在 android WebView 中保存登录数据吗?

php - 如何使用 php FCM 同时处理对 Android 和 iOS 的不同通知负载?

android - 使用安卓应用程序控制外设

xml - 需要澄清有关 xml 模式 "all"标记(这是 libxml2 错误吗?)

c# - 如何使用 C# 合并 2 个 XML 文件

c# - 是否有 XSD 驱动的随机 XML 测试数据生成器?

android - 使用 Twitter4j-4.0.2 消费和过滤推文

javascript - KitKat WebView 错误地报告 pageYOffset

android - 有什么方法可以用 spannable 替换 EditText 中的文本,但可以节省值(value)?