大马资讯论坛 - 马来西亚中文资讯平台

 找回密码
 注册
搜索

[解决] Android 广告admob required xml attribute adsize was missing

[复制链接]
发表于 2014-6-3 22:43:31 | 显示全部楼层 |阅读模式
Android 广告admob required xml attribute adsize was missing一直错误。
三个步骤搞定

1. AndroidManifest.xml 加入
a. Google Play services library
b.     <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version"/>
b.     <activity android:name="com.google.android.gms.ads.AdActivity"
             android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
c.   <uses-permission android:name="android.permission.INTERNET"/>
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
可以参考 https://developers.google.com/mobile-ads-sdk/docs/

2. 在你的layout添加adView,记得换上你的ads:adUnitId
放这个》xmlns:ads="http://schemas.android.com/apk/res-auto"在最上面的RelativeLayout
  1.         <RelativeLayout
  2.             android:id="@+id/ad_holder"
  3.             android:layout_width="fill_parent"
  4.             android:layout_height="wrap_content"
  5.             android:layout_alignParentBottom="true"
  6.             android:gravity="bottom" >

  7.             <com.google.android.gms.ads.AdView
  8.                 android:id="@+id/adView"
  9.                 android:layout_width="wrap_content"
  10.                 android:layout_height="wrap_content"
  11.                 ads:adSize="SMART_BANNER"
  12.                 android:layout_centerInParent="true"
  13.                 ads:adUnitId="ca-app-pub-444810351888"                
  14.         />
  15.         </RelativeLayout>
复制代码
3. 在activity的oncreate添加一下代码,记得还你的TestDeviceID,在eclipse的LogChat能找到你的TestDeviceID
  1.             AdView adView = (AdView) this.findViewById(R.id.adView);
  2.             AdRequest adRequest = new AdRequest.Builder()
  3.                 .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
  4.                 .addTestDevice("73DAE75E1FDF791F62C371BD6EA")
  5.                 .build();
  6.             adView.loadAd(adRequest);
复制代码
可以参考 https://developers.google.com/mo ... b/fundamentals#play

手机版|大马资讯论坛  

GMT+8, 2024-3-29 13:21 , Processed in 0.053479 second(s), 13 queries , File On.

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表