2010-09-01 135 views
5

我的廣告根本沒有顯示,我想我已經正確地跟蹤了文檔,但他們仍然不會顯示。該計劃基本上是一個Web視圖,我希望廣告顯示在底部。Admob廣告沒有顯示 - Android

繼承人我佈局文件:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <WebView 
     android:id="@+id/webview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
    <com.admob.android.ads.AdView 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     myapp:backgroundColor="#000000" 
     myapp:primaryTextColor="#FFFFFF" 
     myapp:secondaryTextColor="#CCCCCC" /> 
</LinearLayout> 

任何想法?

編輯:這是我現在有,但它仍然沒有出現很正確:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:myapp="http://schemas.android.com/apk/res/man.utd.headlines" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 
<com.admob.android.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    myapp:backgroundColor="#000000" 
    myapp:primaryTextColor="#FFFFFF" 
    myapp:secondaryTextColor="#CCCCCC" /> 
<WebView 
    android:id="@+id/webview" 
    android:layout_above="@id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 
</RelativeLayout> 
+0

它看起來你的佈局是不正確的。你的webview佔用了所有的屏幕。嘗試切換webview和adview,並將adview的高度更改爲wrap_content而不是fill_parent。 – bhups 2010-09-01 09:03:02

+0

'Admob'中的錯誤可能是! – 2014-06-29 12:04:28

回答

6

您的問題是,web視圖將採取所有屏幕上的空間,沒有空間留下廣告。

LinearLayout將按照先到先得的原則分配空間。如果第一次查看通吃的空間第二種觀點不會得到任何空間..

我會用一個RelativeLayout,並添加第一個增添了layout_alignParentBottom屬性,然後用layout_above="id for the adds"添加web視圖。這將確保添加總是在屏幕的底部,即使webview不會佔用所有空間,webview將始終高於添加。

+0

感謝您的支持 - 我似乎走在了正確的軌道上,但我仍然沒有看到廣告 - 我需要更改填充父項嗎?我仍然試圖讓我的頭腦圍繞Android佈局,但感謝迄今爲止的巨大幫助。 – user319940 2010-09-01 14:17:04

+0

廣告應該是wrap_content作爲height和fill_parent的寬度,我假設。 Webview可以保持fill_parent。這應該導致佈局的增加儘可能的大,並且webview儘可能大。 – Janusz 2010-09-01 14:29:52

+0

嗯,它仍然沒有工作 - 只是爲了確認 - 這一切看起來是否正確? (見更新) – user319940 2010-09-01 14:41:43

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
    android:layout_width="fill_parent" android:id="@+id/rltvLayout1" 
    android:layout_height="fill_parent"> 
    <LinearLayout android:id="@+id/linearLayoutwebview" 
     android:layout_height="wrap_content" android:layout_width="wrap_content" 
     android:orientation="vertical"> 
     <WebView android:id="@+id/webView1" 
      android:layout_width="fill_parent" android:layout_height="fill_parent" 
      android:fitsSystemWindows="true" /> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
     android:id="@+id/ad_layout" android:layout_height="wrap_content" 
     android:gravity="bottom" android:layout_alignParentBottom="true" 
     android:layout_alignBottom="@+id/home_layout"> 
     <com.google.ads.AdView android:layout_width="wrap_content" 
      android:layout_height="wrap_content" ads:adUnitId="put here your ID" 
      ads:adSize="BANNER" android:id="@+id/adView" ads:refreshInterval="60" /> 

    </LinearLayout> 
</RelativeLayout> 
1

我有同樣的問題,我固定它是這樣的: 的LinearLayout爲主要佈局,裏面的LinearLayout(爲廣告)和網頁視圖,設置WRAP_CONTENT在LinearLayout中的廣告,因此,它會首先展示一個廣告,然後屏幕的其餘部分將成爲web視圖。我的 例如:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
    <LinearLayout 
android:id="@+id/addmob" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
></LinearLayout> 
<WebView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/webview" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"/> 



</LinearLayout>