我有一个简单的Activity
,其WebView
。我想整合Facebook Audience Network广告(现在是webview底部的横幅)。广告正在加载,但是当我将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/res-auto"
android:id="@+id/linearLayoutWebView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true" />
<RelativeLayout
android:id="@+id/adViewContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
WebView mWebView;
String site_adresi;
String site_adi;
final Activity activity = this;
private AdView adView;
private String PLACEMENT_ID = "1234567890XYZ";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setSupportZoom(true);
String fullLink = "http://" + site_adresi;
mWebView.loadUrl(fullLink);
mWebView.setWebViewClient(new HakkiWebViewClient());
//FACEBOOK ADS starts
RelativeLayout adViewContainer = (RelativeLayout) findViewById(R.id.adViewContainer);
adView = new AdView(this, PLACEMENT_ID, AdSize.BANNER_320_50);
adViewContainer.addView(adView);
adView.loadAd();
adView.setAdListener(new AdListener() {
@Override
public void onAdClicked(Ad arg0) {
Log.d("FB_REK_DURUM","clicked");
}
@Override
public void onAdLoaded(Ad arg0) {
Log.d("FB_REK_DURUM","loaded");
}
@Override
public void onError(Ad arg0, AdError arg1) {
Log.d("FB_REK_DURUM","load error");
}
});
AdSettings.addTestDevice("b7fe33fe01c902446ba72e07eecdd886");
// Request to load an ad
adView.loadAd();
//FACEBOOK ADS ends
}
答案 0 :(得分:1)
将外部布局更改为RelativeLayout,然后将adViewContainer放置在WebView顶部的底部。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/linearLayoutWebView"
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:fitsSystemWindows="true" />
<RelativeLayout
android:id="@+id/adViewContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>