admob android帮助

时间:2011-08-15 22:08:09

标签: android-layout admob android-linearlayout relativelayout

我在将布局正确放入布局时遇到问题。无论我怎么说它我似乎根本看不到广告。这是2个布局...

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的代码是     机器人: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

的java代码
    // 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); 

1 个答案:

答案 0 :(得分:0)

在你的main.xml中按照下面的例子添加一个AdView,也不要忘记添加               的xmlns:广告= “http://schemas.android.com/apk/lib/com.google.ads” 到主要的LinearLayout定义,并将MY_AD_UNIT_ID替换为您的adMob发布商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上的更多示例。