Перекрывающиеся с Admob и Webview - PullRequest
1 голос
/ 16 ноября 2011

Впервые я разрабатываю приложение для Android, и пока оно идет очень хорошо, за исключением одной вещи. Я сделал макет веб-просмотра, и я хотел показывать рекламу в приложении. Поэтому я добавил рекламу AdMob, и они работают очень хорошо. Но есть одна проблема.

AdMob покрывает часть 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", но затем приложение закрылось ... Так что я действительно надеюсь, что кто-нибудь может мне помочь, поскольку я ищу его часами: (

1 Ответ

3 голосов
/ 16 ноября 2011

Кажется, что layout_above должно работать, но если это действительно ваш полный макет, на мой взгляд, самый простой способ - заменить RelativeLayout на LinearLayout, поскольку вы только выкладываете эти виды в в любом случае, а затем дать основную часть веса. Я бы, вероятно, также избавился от 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>
...