我使用谷歌播放服务lib,这是我的 main xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="MyUnitID" />
</LinearLayout>
这是我的清单(不确定它是否非常好......在那里有很多狗屎)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.noamro.bloo"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
在main.xml图形布局中我可以看到红色框表示“必需的XML属性”adSize“缺失” 我确实设置了adSize ...... 我只是希望当我的游戏工作时,菜单状态会有广告。 请帮忙
答案 0 :(得分:0)
我会改变
ads:adSize="BANNER"
要
ads:adSize="SMART_BANNER"
否则广告不会根据屏幕尺寸调整大小(除非您想要的是这样),并且在java文件的onCreate方法中添加:
adView = new AdView(this);
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
//.addTestDevice("") - You'll find your device ID in the LogCat output starting with a # it is recommended that you have a test device but it's up to you
.build();
adView.loadAd(adRequest);