这是我第一次开发 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 替换
因为无论如何您只是将这些 View 排成一行,然后给主要部分赋予权重。我可能还会摆脱 RelativeLayout
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/