Как разместить рекламу под веб-представлением

Я хочу разместить рекламный баннер сети Facebook Audience под веб-представлением. Я не хочу, чтобы реклама перекрывала мой веб-просмотр. Я не смог реализовать это в течение нескольких дней.

Вот мой файл макета, в котором я разместил рекламу после веб-просмотра в ограниченном макете.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/web_view_relative_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">

    <View
        android:id="@+id/divider"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:background="?android:attr/listDivider"
        app:layout_constraintTop_toTopOf="parent" />

    <WebView
        android:id="@+id/web_view_documentation"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <RelativeLayout
        android:id="@+id/native_banner_ad_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent" />

</android.support.constraint.ConstraintLayout>

Я разместил AppBarLayout над веб-просмотром. Если я добавлю ограничения, мой веб-просмотр начнет перекрываться панелью приложения.

Высота и ширина моего веб-просмотра установлены на match_parent. Я хочу, чтобы мой веб-просмотр занимал все пространство, оставшееся после объявления. Таким образом, в основном, если мое объявление имеет высоту 100dp, веб-просмотр должен заполнять оставшееся пространство без перекрытия или перекрытия. Заранее спасибо.




Ответы (2)


Вы можете поместить представления в вертикальную цепочку, чтобы WebView занимало все оставшееся место, когда высота контейнера RelativeRelayout для объявления установлена ​​на wrap_content:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/web_view_relative_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">

    <View
        android:id="@+id/divider"
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:background="?android:attr/listDivider"
        app:layout_constraintBottom_toTopOf="@id/web_view_documentation"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <WebView
        android:id="@+id/web_view_documentation"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/native_banner_ad_container"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/divider"/>

    <RelativeLayout
        android:id="@+id/native_banner_ad_container"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/web_view_documentation"/>

</android.support.constraint.ConstraintLayout>
person Pawel Laskowski    schedule 21.07.2018
comment
Спасибо за помощь. Оно работает. Я добавлю еще один ответ, который я недавно нашел, как это сделать, используя только относительный макет. - person hamzaali; 21.07.2018

Просто замените файл макета следующим, и он заработает.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main">

    <WebView
        android:id="@+id/web_view_documentation"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:layout_above="@id/native_banner_ad_container"/>

    <RelativeLayout
        android:id="@+id/native_banner_ad_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"/>
</RelativeLayout>
person hamzaali    schedule 21.07.2018