0

我有一个简单ActivityWebView. 我想整合 Facebook Audience Network 广告(现在是 webview 底部的横幅)。广告加载良好,但是当我将 webview 添加到页面时,它会放置所有 height 和 width。如何在我的网页视图上但在底部显示我的广告布局

<?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

    }
4

1 回答 1

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>
于 2015-12-12T07:11:01.757 回答