The layout is simple, One WebView and a Banner(AD).
I wrote an XML like below:
<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>
And here's a code to create a banner runtime.
// 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();
This code won't work, the banner is displayed outside of the screen.
So, what I looking for is android:layout_height="match_parent - 50dp"
just like calc
in CSS.
There is no such option of doing android:layout_height="match_parent - 50dp"
in Android.
For integrating the Facebook audience network, you need to create an xml first with the banner_container
. You can consider using a different layout structure like the following, using a 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>