我在正確地將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);
是否有一些Java代碼添加adView?因爲它是我可以看到什麼都沒有涉及到admob ... – Smugrik
是linearLayout指向adm代碼在java代碼。這是我在admob網站上發現的唯一工作示例,所以我堅持使用它。一切似乎都在自己的工作。這裏是java中的代碼.... – woozie
javacode是在update1中的第一篇文章。 – woozie