android:xml格式的广告编码,执行时无法显示任何广告
我尝试将com.google.ads.AdView添加到xml部分,xml编码如下:android:xml格式的广告编码,执行时无法显示任何广告,android,admob,tablelayout,Android,Admob,Tablelayout,我尝试将com.google.ads.AdView添加到xml部分,xml编码如下: <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" android:id="@+id/tableLayout" android:layout_width="m
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_color"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="5dp"
android:stretchColumns="*" >
<TableRow
<Button android:id="@+id/equal"
style="@style/Eq_button_style"
android:text="=">
</Button>
</TableRow>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="a123123123123c" //this ID is confirmed correct
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, xxxxxxxxxxxxxxxxx" //this ID is confirmed correct
ads:loadAdOnCreate="true"/>
</TableLayout>
10-10 01:45:16.360: I/GATE(16797): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
10-10 01:45:16.365: D/webviewglue(16797): nativeDestroy view: 0x3ef6f0
10-10 01:45:16.365: E/Ads(16797): An error occurred while destroying an AdWebView:
10-10 01:45:16.365: E/Ads(16797): java.lang.NullPointerException
10-10 01:45:16.365: E/Ads(16797): at android.webkit.WebView.setWebViewClient(WebView.java:5168)
10-10 01:45:16.365: E/Ads(16797): at com.google.ads.internal.AdWebView.destroy(SourceFile:252)
10-10 01:45:16.365: E/Ads(16797): at com.google.ads.internal.c$e.run(SourceFile:191)
10-10 01:45:16.365: E/Ads(16797): at android.os.Handler.handleCallback(Handler.java:605)
10-10 01:45:16.365: E/Ads(16797): at android.os.Handler.dispatchMessage(Handler.java:92)
10-10 01:45:16.365: E/Ads(16797): at android.os.Looper.loop(Looper.java:137)
10-10 01:45:16.365: E/Ads(16797): at android.app.ActivityThread.main(ActivityThread.java:4511)
10-10 01:45:16.365: E/Ads(16797): at java.lang.reflect.Method.invokeNative(Native Method)
10-10 01:45:16.365: E/Ads(16797): at java.lang.reflect.Method.invoke(Method.java:511)
10-10 01:45:16.365: E/Ads(16797): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-10 01:45:16.365: E/Ads(16797): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-10 01:45:16.365: E/Ads(16797): at dalvik.system.NativeStart.main(Native Method)
10-10 01:45:16.365: I/Ads(16797): onReceiveAd()
10-10 01:45:16.460: D/dalvikvm(16797): GC_CONCURRENT freed 424K, 6% free 9580K/10119K, paused 2ms+11ms
10-10 01:45:16.460: W/Ads(16797): Not enough space to show ad! Wants: <480, 75>, Has: <464, 708>
问题确实是:
W/Ads(16797): Not enough space to show ad! Wants: <480, 75>, Has: <464, 708>
W/Ads(16797):没有足够的空间显示广告!想要:,拥有:
对于该设备,您需要整个屏幕宽度来显示纵向广告。部分问题是您的TableLayout上的android:padding=“5dp”。这应该是一个布局问题。 试试这个
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/background_color"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="5dp"
android:stretchColumns="*" >
<TableRow>
<Button
android:id="@+id/equal"
style="@style/Eq_button_style"
android:text="=" >
</Button>
</TableRow>
</TableLayout>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a123123123123c"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, xxxxxxxxxxxxxxxxx" />
</LinearLayout>
非常感谢!!广告终于出现了。我想进一步问一下,上面的内容是为了测试,如果它将作为免费应用发布在市场上,会有什么不同吗?我需要修改任何编码吗?(如移除测试设备ID?)此外,即使可以显示广告,logcat仍有一些红色“E”部分。如上所述更新了logcat。此“E”是否会影响应用程序的正常运行?销毁AdWebView时发生错误:错误是SDK捕获的Android WebView错误,并记录为错误(应记录为警告)。你在这里应该很好。对于测试广告,不管您是否保留测试设备ID代码,事实上,只有模拟器和Physcal设备将获得测试广告。您朋友的设备将获得具有相同代码的实时广告。您在发布前是否要删除testDevices的调用。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TableLayout
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/background_color"
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="5dp"
android:stretchColumns="*" >
<TableRow>
<Button
android:id="@+id/equal"
style="@style/Eq_button_style"
android:text="=" >
</Button>
</TableRow>
</TableLayout>
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a123123123123c"
ads:loadAdOnCreate="true"
ads:testDevices="TEST_EMULATOR, xxxxxxxxxxxxxxxxx" />
</LinearLayout>