新的admob Express Native广告因IllegalStateException而失败

Joh*_*ith 6 android admob android-layout native-ads

我一直在尝试将快速原生广告整合到我的应用程序中.在快速原生广告文档中,我读过它们在以FULL_WIDTH广告尺寸显示时效果最佳.我尝试将广告尺寸设置为FULL_WIDTH,但失败并出现IllegalStateException:

Caused by: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
Run Code Online (Sandbox Code Playgroud)

这是我的xml代码:

<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="FULL_WIDTH"
ads:adUnitId="@string/native_ad_unit"/>
Run Code Online (Sandbox Code Playgroud)

广告单元是正确的,它适用于其他广告尺寸,如320x150等.

我的实施有问题吗?

干杯

Joh*_*ith 19

我找到了一个解决方案,如果您像这样使用它将会起作用:

<com.google.android.gms.ads.NativeExpressAdView
 android:id="@+id/adView"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 ads:adSize="FULL_WIDTHx80"
 ads:adUnitId="@string/native_ad_unit"/>
Run Code Online (Sandbox Code Playgroud)