Как сделать место для баннера - PullRequest
3 голосов
/ 24 апреля 2019

Простая компоновка, One WebView и баннер (AD).

Я написал XML, как показано ниже:

<LinearLayout
    android:id="@+id/banner_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentBottom="true"
    android:orientation="vertical">
    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></WebView>
</LinearLayout>

А вот код для создания баннера во время выполнения.

// This code is copied & pasted from AudienceNetwork's guide page
adView = new AdView(this, "PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
adContainer.addView(adView);
adView.loadAd();

Этот код не работает, баннер отображается за пределами экрана. Итак, я ищу android:layout_height="match_parent - 50dp", как calc в CSS.

Ответы [ 2 ]

4 голосов
/ 24 апреля 2019

Нет такой возможности сделать android:layout_height="match_parent - 50dp" в Android.

Для интеграции сети аудитории Facebook сначала необходимо создать xml с banner_container. Вы можете рассмотреть возможность использования другой структуры макета, например, следующей, используя RelativeLayout.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <WebView
        android:id="@+id/webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/banner_container" />

    <LinearLayout
        android:id="@+id/banner_container"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:orientation="vertical" />
</RelativeLayout>
1 голос
/ 20 мая 2019

Вы можете использовать существующий макет, просто добавив LinearLayout ниже Webview.Не забудьте добавить android: layout_weight = "1" в Webview

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical">
<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"></WebView>

<LinearLayout
    android:id="@+id/banner_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" />

, а затем использовать существующий код

adView = new AdView(this, "PLACEMENT_ID", AdSize.BANNER_HEIGHT_50);
LinearLayout adContainer = (LinearLayout) findViewById(R.id.banner_container);
adContainer.addView(adView);
adView.loadAd();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...