2014-05-22 109 views
0

現在我正在創建一個Android應用程序,該應用程序使用HTML5Webview播放視頻。我從此下載HTML5webview https://code.google.com/p/html5webview/在HTML5Webview中添加admob時沒有足夠的廣告空間

現在,我想在此應用程序中添加admob橫幅。但是,當我這樣做時,我有一個問題。我的廣告未顯示,因爲「廣告空間不足」。 SS錯誤消息:http://prntscr.com/3lk1t0

在Html5web視圖中,佈局使用FrameLayout。我認爲,問題是關於佈局。我搜索其他引用以在FrameLayout中添加admob,但所有引用都使用RelativeLayout。

如何解決此問題?

這是我的XML佈局:

<?xml version="1.0" encoding="utf-8"?> 

<FrameLayout android:id="@+id/fullscreen_custom_content" 
    android:visibility="gone" 
    android:background="@color/black" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 

/> 
<LinearLayout android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

<FrameLayout android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
    /> 

    <com.google.android.gms.ads.AdView android:id="@+id/adView" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:paddingLeft="0dp" 
         android:paddingRight="0dp" 
         ads:adSize="BANNER" 
         ads:adUnitId="*****"/> 
</LinearLayout></FrameLayout> 

,這是我的活動課,你可以透過Dropbox看到 - > Klik for Activity class

我的問題是,如何如果我的代碼是這樣的,請添加admob。以前感謝。

回答

1

此佈局有幾個問題。

  1. 您在外層有多個佈局。你應該只有一個。擺脫第一個FrameLayout元素。
  2. 您完成一個結束FrameLayout標記,不匹配。這使XML結構無效,Android LayoutManager無法加載此佈局。刪除最後的</FrameLayout>標籤。
  3. 您已將LinearLayout的高度指定爲match_parent。這告訴LayoutManager使該元素消耗其父項的所有高度。這就是AdView沒有空間的原因。將其更改爲wrap_content並添加layout_weight="1"屬性以使LayoutManager擴展該元素以填充任何未使用的空間,以便WebView佔用AdView未使用的任何空間。

即是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <FrameLayout android:id="@+id/main_content" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
    /> 

    <com.google.android.gms.ads.AdView android:id="@+id/adView" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:paddingLeft="0dp" 
         android:paddingRight="0dp" 
         ads:adSize="BANNER" 
         ads:adUnitId="*****"/> 
</LinearLayout> 
相關問題