4

我已将 xml 中的谷歌广告声明为

<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >


        <com.google.ads.AdView
             xmlns:ads="http://schemas.android.com/apk/lib/com.admobdemo"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="a150cb2e31846cf" 
        ads:loadAdOnCreate="true"
        ads:testDevices="AVD_for_4in_WVGA_Nexus_S,5554" />


    </RelativeLayout>

我已经在 XML 和清单文件中声明了命名空间。

我在我的活动中声明为

AdView adView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest();
        adRequest.setTesting(true);

        adView.loadAd(adRequest);

但是当我运行我的应用程序时,我得到的响应为

adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":0,"u_sd":1.5,"u_w":480,"simulator":1,"msid":"com.netserv.Pungry","cap":"m,a","js":"afma-sdk-a-v4.0.2","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","net":"ed","app_name":"4.0.2.android.com.netserv.Pungry","hl":"en","u_h":800,"testing":1,"u_so":"p","u_audio":4});</script></head><body></body></html>

但它没有显示在输出中,我收到错误

03-19 13:43:46.190: E/Ads(4983): AdView missing required XML attribute adUnitId.

我能知道我的代码中的错误是什么吗?

谢谢:)

4

1 回答 1

0

当您想展示广告时,在主布局中采用一种布局

        <LinearLayout
            android:id="@+id/addlay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>

并在java文件中

        AdView adView = new AdView(this, AdSize.BANNER, "xxxxxxxxxxxxxxx");
        LinearLayout addLay = (LinearLayout) findViewById(R.id.addlay);

        AdRequest adRequest = new AdRequest();
        // adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
        addLay.addView(adView);
        adView.loadAd(adRequest);

你检查过这个吗 在此处输入图像描述

有时项目清洁也有效..

你能看到这个吗

在此处输入图像描述

于 2013-03-19T14:02:46.297 回答