简体   繁体   中英

placing Facebook Audience Network ads at the bottom of webview

I have a simple Activity which has a WebView . I want to integrate Facebook Audience Network ads (for now a banner at the bottom of webview). Ad is loading well but when I add webview to page, it placing all height and width . How can I show my ads layout over my webview but at the bottom?

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

    }

Change the outer layout to RelativeLayout, then position the adViewContainer at the bottom on top of the 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM