布局很简单,一个WebView和一个Banner(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",就像CSS中的calc一样。

最佳答案

在Android中,没有此类选项可以执行android:layout_height="match_parent - 50dp"

为了集成Facebook受众网络,您需要首先使用banner_container创建一个xml。您可以考虑使用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>

10-08 06:22
查看更多