2015-10-09 52 views

回答

2

你可以用它在一個相對佈局,並設置AdView的如android:layout_alignParentBottom

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/res-auto" 
    android:orientation="vertical" android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <com.google.android.gms.ads.AdView 
     android:id="@+id/adView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     ads:adUnitId="@string/admob_unit_id" ads:adSize="BANNER" /> 

    <WebView android:id="@+id/webView" android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
    </WebView> 

</RelativeLayout> 
+0

我看了一些這裏'android:layout_alignParentBottom'已被棄用,這是真的嗎? – joke4me

+0

廣告橫幅現在不再顯示;-) – joke4me

0

可以使用的LinearLayout垂直方向,那麼你可以先找到該網頁視圖,web視圖放的權重4(這是根據所有其他元素的重量總和在屏幕上佔據的部分,這裏是6個重量,屏幕分成6塊,用於webview 4或任何你想要的),然後你使用admob,體重爲2.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:showIn="@layout/activity_main" tools:context=".MainActivity" 
    android:orientation="vertical"> 


    <WebView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="4" 
     android:id="@+id/webView" /> 

    <com.google.android.gms.ads.AdView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="2" 
     android:id="@+id/adView" 
     ads:adUnitId="@string/admob_unit_id" ads:adSize="BANNER" /> 

</LinearLayout>