我尝试了很多事情,但没有任何帮助。我的问题是我的admob ad
没有显示,而LogCat
正在写这个:
03-19 12:30:56.140: E/Ads(790): Not enough space to show ad! Wants: <480, 75>, Has: <432, 690>
03-19 12:30:56.140: E/Ads(790): Not enough space to show ad! Wants: <480, 75>, Has: <432, 357>
问题可能是模拟器,而不是代码?对任何帮助都会非常感激
我的manifest.xml
:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.gosha.whymod.MainActiviti"
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.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
MainActivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActiviti" >
<Button
android:id="@+id/knopka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="142dp"
android:gravity="center"
android:onClick="onClick"
android:text="Get answer now" />
<TextView
android:id="@+id/texte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:gravity="center"
android:text="Why modern art is so strange?"
android:textAppearance="?android:attr/textAppearanceLarge" />
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/knopka"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-1837185169360297/2930943167"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR" />
答案 0 :(得分:1)
替换
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/knopka"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-1837185169360297/2930943167"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR" />
带
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/knopka"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-1837185169360297/2930943167"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR" />
</ScrollView>
答案 1 :(得分:1)
从RelativeLayout中删除paddingLeft和paddingRight。这就是导致缩小显示区域的原因。
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
答案 2 :(得分:0)
您正在 HDPI 设备上进行测试, AdView 需要480x75像素才能显示广告。 BANNER 尺寸
在您的XML布局文件中,父 RelativeLayout (似乎自动创建)左右填充值。这将产生比实际屏幕分辨率更小的活动。因此,嵌入式儿童 AdView 只能获得比480p更小的屏幕尺寸
尝试将父 FrameLayout 与 RelativeLayout 和 AdView 作为子项,因此 AdView 将显示为 RelativeLayout
上的叠加层<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActiviti" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<Button android:id="@+id/knopka"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="142dp"
android:gravity="center"
android:onClick="onClick"
android:text="Get answer now" />
<TextView android:id="@+id/texte"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:gravity="center"
android:text="Why modern art is so strange?"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<com.google.ads.AdView android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/knopka"
ads:adSize="SMART_BANNER"
ads:adUnitId="ca-app-pub-1837185169360297/2930943167"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR" />