2011-08-15 101 views
0

我在正確地將admob放入佈局時遇到了問題。不管我怎麼說,我都無法看到廣告。這裏有2個佈局...admob android幫助

main.xml中

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/linearLayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#0000"> 
<ListView 
android:id="@+id/android:list" 
android:background="#0000" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:dividerHeight="1dip"/> 
</LinearLayout> 

layout2.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="?android:attr/listPreferredItemHeight" 
android:padding="10dip" 
android:background="#0000"> 
<TableLayout 
android:layout_width="fill_parent" 
android:layout_weight="1" 
android:layout_height="fill_parent" 
android:stretchColumns="*" 
android:background="#0000"> 
<TableRow> 
<TextView 
android:id="@+id/description" 
android:padding="2dip" 
android:textColor="#ffff" 
android:background="#0000"/> 
</TableRow> 
</TableLayout> 
</LinearLayout> 

和代碼到AdMob的Java是Android的 :ID =「@ + ID/linearLayout「 已經在主佈局中。問題是,它不顯示,但如果我做了一個新的項目,只有admob java部分與網上佈局,我可以看到廣告。

是的,我已經在主要

<activity android:name="com.google.ads.AdActivity" 
android:configChanges="keyboard|keyboardHidden|orientation"/> 
</application> 
<uses-permission android:name="android.permission.INTERNET"/> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> 

也有人告訴我使用相對佈局,但也並不工作,除非我這樣做不對加入適當的代碼。希望有人能幫助!

UPDATE1: 這裏是使用@ + ID/LinearLayout中給AdMob

// Lookup R.layout.main 
    LinearLayout layout = 
    (LinearLayout)findViewById(R.id.linearLayout); 
    // Create the adView 
    // Please replace MY_BANNER_UNIT_ID with your AdMob Publisher ID 
    AdView adView = new AdView(this, AdSize.BANNER, "a14e458091154df"); 
    // Add the adView to it 
    layout.addView(adView); 
    // Initiate a generic request to load it with an ad 
    AdRequest request = new AdRequest(); 
    request.setTesting(true); 
    adView.loadAd(request); 
+0

是否有一些Java代碼添加adView?因爲它是我可以看到什麼都沒有涉及到admob ... – Smugrik

+0

是linearLayout指向adm代碼在java代碼。這是我在admob網站上發現的唯一工作示例,所以我堅持使用它。一切似乎都在自己的工作。這裏是java中的代碼.... – woozie

+0

javacode是在update1中的第一篇文章。 – woozie

回答

0

在您的main.xml中添加的AdView按照下面的示例中的Java代碼,也不要忘了加在 的xmlns:廣告= 「http://schemas.android.com/apk/lib/com.google.ads」 到主的LinearLayout定義,並與您的AdMob發佈商編號取代MY_AD_UNIT_ID

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
android:id="@+id/linearLayout" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#0000"> 
    <com.google.ads.AdView android:id="@+id/adView" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         ads:adUnitId="MY_AD_UNIT_ID" 
         ads:adSize="BANNER" 
         ads:loadAdOnCreate="true"/> 
<ListView 
android:id="@+id/android:list" 
android:background="#0000" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:dividerHeight="1dip"/> 
</LinearLayout> 

而且查看更多this page上的示例。

+0

我收到了一個力量。 javacode在第一篇文章中的update1中。 – woozie

+0

請發佈LogCat堆棧跟蹤,應該有關於崩潰原因的信息... – Smugrik